//
//  CXmppRequestMgr.m
//  wanzhaoIM
//
//  Created by liuyuantao on 15/5/29.
//  Copyright (c) 2015年 liuyuantao. All rights reserved.
//

#import "CXmppRequestMgr.h"
#import "XMPP.h"
#import "MicroDef.h"

#import "CServerSettingMgr.h"
#import "CServerSettingModel.h"
#import "NSString+MD5Addition.h"
//#import "CAccountMgr.h"
//#import "CAccountModel.h"
#import "CFolderMgr.h"
#import "CContactMgr.h"
#import "CContactModel.h"
#import "SDWebImageManager.h"
#import "ChildHoodService.h"
#import "UIUtil.h"
#import "CGroupModel.h"
#import "CMessageModel.h"
#import "CMessageMgr.h"
#import "VoiceConverter.h"
#import "DownloadFileManager.h"
#import "MBProgressHUD+WZ.h"
#import "JKAlertDialog.h"
#import "NSString+DESAndBase64.h"
#import "CShareCommentDelMgr.h"
#import "CShareDelMgr.h"
#import "CShareMgr.h"
#import "CShareCommentMgr.h"
#import "EFengContent.h"
#import "EFengShareDel.h"
#import "EFengShareCommentDel.h"
#import "EFengShare.h"
#import "MJExtension.h"
#import "UIImage+Category.h"
#import "CSharePersonMgr.h"


@interface CXmppRequestMgr()
{
    NSOperationQueue *_queen;
}


@end


@implementation CXmppRequestMgr


- (NSMutableArray *)operationArray
{
    if (_operationArray == nil) {
        _operationArray = [NSMutableArray array];
    }
    return _operationArray;
}

- (NSMutableArray *)contactArray
{
    if (_contactArray == nil) {
        _contactArray = [NSMutableArray array];
    }
    return _contactArray;
}

- (NSMutableArray *)depArray
{
    if (_depArray == nil) {
        _depArray = [NSMutableArray array];
    }
    return _depArray;
}
//- (NSMutableDictionary *)downLoadDict
//{
//    if (_downLoadDict == nil) {
//        _downLoadDict = [NSMutableDictionary dictionary];
//    }
//    return _downLoadDict;
//}

+(CXmppRequestMgr *)shareInstance
{
    static CXmppRequestMgr *instance  = nil;
    static dispatch_once_t dispatch_onces;
    if(instance  == nil)
    {
        dispatch_once(&dispatch_onces, ^{
            
            instance = [[CXmppRequestMgr alloc] init];
        });
    }
    return instance;
}

-(id)init
{
    self = [super init];
    {
        _queen = [[NSOperationQueue alloc] init];
        self.messageMgr = [[CMessageMgr alloc] init];
        self.downMgr = [[DownloadFileManager alloc] init];
        self.shareQueue = [[NSOperationQueue alloc] init];
        self.shareQueue.maxConcurrentOperationCount = 5;
    }
    return self;
}


-(void)checkVersion
{
//    CServerSettingMgr *serverMgr = [[CServerSettingMgr alloc] init];
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSString *localServerAddr = serverSetting.IMIp;
    NSInteger openFirePort = serverSetting.IMPort;
    
//    NSString *version = [USER_DEFAULT stringForKey:SERVERVERSION];
//    if (M_ISSTRNULL(version)) {
//        version = @"0.0.0";
//    }

//    NSLog(@"%@",[USER_DEFAULT stringForKey:APP_VERSION]);
    NSString *urlStr = [NSString stringWithFormat:@"http://%@:%zd/imconsole/mobileFile_checkVersion.action?type=ios&version=%@", localServerAddr, openFirePort,[USER_DEFAULT stringForKey:APP_VERSION]];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
//    operation.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/json"];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSString *str = [USER_DEFAULT stringForKey:APP_VERSION];
        if ([responseObject[@"version"] isEqualToString:[USER_DEFAULT stringForKey:APP_VERSION]]) {
            
        } else {
            if ([responseObject[@"isNew"] boolValue]) {
                
                if ([responseObject[@"downLoad"] boolValue]) {
                    
                   [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[responseObject[@"url"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
                } else {
                   [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[responseObject[@"url"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
                }
                
            }
        }
//        [USER_DEFAULT setObject:responseObject[@"version"] forKey:SERVERVERSION];
//        [USER_DEFAULT synchronize];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//        NSLog(@"failed!");
//        [MBProgressHUD showError:@"网络错误"];
    }];
    [_queen addOperation:operation];
}


- (void)getUpdateInfo
{
//    CServerSettingMgr *serverMgr = [[CServerSettingMgr alloc] init];
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    
    NSString *localServerAddr = serverSetting.IMIp;
    NSInteger openFirePort = serverSetting.IMPort;
    
    NSRange range ;
    range.location = 8;
    range.length = 16;
    NSString *paddword = [[@"88888888" stringFromMD5] substringWithRange:range];
    CAccountModel *acc = [[CFolderMgr shareInstance].accMgr getRecentlyLoginAccount];
    
    
    NSString *urlStr = [NSString stringWithFormat:@"http://%@:%zd/imconsole/general_getUserInfoState.action?userName=%@&password=%@&userId=%@&timestamp=%@", localServerAddr, openFirePort,@"admin", paddword,acc.userId,acc.info];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    
    
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
       
        NSDictionary *dict = responseObject;
        
        if (dict == nil) {
            return ;
        }
//        NSLog(@"%@",dict);
        if ([dict[@"img"] length] > 0) {
            [[SDWebImageManager sharedManager].imageCache removeImageForKey:[[CXmppRequestMgr shareInstance] DownHeadFileWithContact:dict[@"img"]]];
            [[SDWebImageManager sharedManager].imageCache removeImageForKey:[[CXmppRequestMgr shareInstance] DownHeadFileWithContact:dict[@"img"]] fromDisk:YES];

        }
       
        id index = dict[@"info"];
        if ([index isKindOfClass:[NSDictionary class]]) {
            NSString *userCode = [index objectForKey:@"userCode"];
            CContactMgr *conMgr = [[CContactMgr alloc] init];
            CContactModel *contactModel = [conMgr loadContactWithUserCode:userCode];
            contactModel.DEPTID = [index objectForKey:@"deptId"];
            contactModel.UserID = [index objectForKey:@"id"];
            [[SDWebImageManager sharedManager].imageCache removeImageForKey:[[CXmppRequestMgr shareInstance] DownHeadFileWithContact:contactModel.UserID]];
            [[SDWebImageManager sharedManager].imageCache removeImageForKey:[[CXmppRequestMgr shareInstance] DownHeadFileWithContact:contactModel.UserID] fromDisk:YES];
            contactModel.UserName = [index objectForKey:@"realName"];
            contactModel.EXtenSion = [index objectForKey:@"extension"];
            contactModel.Autograph = [index objectForKey:@"autograph"];
            contactModel.Position = [index objectForKey:@"position"];
            contactModel.RoleID = [index objectForKey:@"roleId"];
            contactModel.Telephone = [index objectForKey:@"telephone"];
            contactModel.MobileTelephone = [index objectForKey:@"mobilePhone"];
            contactModel.Email = [index objectForKey:@"email"];
            contactModel.HeadPortrait = [index objectForKey:@"HeadPortrait"];
            contactModel.DEPNAME = [index objectForKey:@"dept"];
            contactModel.SEX = [index objectForKey:@"sex"];
            contactModel.address = [index objectForKey:@"address"];
            contactModel.birthDay = [index objectForKey:@"birthday"];
            
            [conMgr updateContact:contactModel];
        }
        
        acc.info = [NSString stringWithFormat:@"%@",[dict objectForKey:@"timestamp"]];
        [[CFolderMgr shareInstance].accMgr updateAccount:acc];


    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        
    }];
    [_queen addOperation:operation];

}

- (void)uploadWithContentData:(NSData *)contentData fileNmae:(NSString *)fileName userId:(NSString *)userId dataType:(NSString *)dataType fileType:(NSString *)fileType successHandel:(void(^)(NSURLSessionDataTask *task, id responseObject))successHandle filarueHandle:(void(^)(NSURLSessionDataTask *task, NSError *error))failureHandle progressHandle:(void(^)(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend))processHandle
{
    
    if (contentData == nil) {
        return;
    }

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NetAndAudioModel *netAndAudio = [[NetAndAudioModel alloc] init];
    netAndAudio.manager = manager;
    netAndAudio.serFileName = fileName;
    [self.operationArray addObject:netAndAudio];
    
    [manager setTaskDidSendBodyDataBlock:^(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
//        processHandle(session, task,bytesSent,totalBytesSent,totalBytesExpectedToSend);
    }];
    
//    CServerSettingMgr *serverMgr = [[CServerSettingMgr alloc] init];
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSString *localServerAddr = serverSetting.IMIp;
    NSInteger openFirePort = serverSetting.IMPort;
    NSString *userName = @"admin";
    
    NSRange range ;
    range.location = 8;
    range.length = 16;
    NSString *paddword = [[@"88888888" stringFromMD5] substringWithRange:range];
    //    NSString *paddword = [@"88888888" stringFromMD5] ;

    
    NSString *urlStr =[NSString stringWithFormat:@"http://%@:%zd/imconsole/mobileFile_fileUpload.action?userName=%@&password=%@&companyId=%@&type=%@&filename=%@&userId=%@&from=ios", localServerAddr, openFirePort, userName, paddword, M_STOREVALUE(serverSetting.companyId), dataType, fileName, userId];
   NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [manager POST:requestUrl parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFileData:contentData name:fileName fileName:fileName mimeType:fileType];
    } success:^(NSURLSessionDataTask *task, id responseObject) {
        successHandle(task, responseObject);
        [self.operationArray removeObject:netAndAudio];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failureHandle(task, error);
        [self.operationArray removeObject:netAndAudio];
    }];
}
//发布分享 text image video textimage
- (void)composeShareWithContact:(CContactModel*)contact sharId:(NSString*)shareId content:(NSString*)content type:(NSString*)type imageArray:(NSArray*)imageArray videoData:(NSData*)data visibleUseId:(NSString*)visibleUseId successHandel:(void (^)(AFHTTPRequestOperation *operation, id responseObject))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failureHandle
{
    __block BOOL noError = YES;
    [USER_DEFAULT setBool:NO forKey:@"sendOK"];
    [USER_DEFAULT synchronize];
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSRange range ;
    range.location = 8;
    range.length = 16;
    NSString *paddword = [[@"88888888" stringFromMD5] substringWithRange:range];
    
    NSString *timeStamp = [UIUtil getCurrentTimeStamp];
    NSString *fileName = nil;
    NSMutableArray *imageNameArray = [NSMutableArray array];
    NSMutableArray *videoNameArray = [NSMutableArray array];
    NSMutableArray *operationArray = [NSMutableArray array];
    for (int i = 0; i < imageArray.count; i ++) {
        UIImage *image = imageArray[i];
        NSData *imgData = UIImageJPEGRepresentation(image, 0.5f);
        fileName = [NSString stringWithFormat:@"%@___%@___%zd.jpg",contact.UserID,timeStamp,i];
        NSDictionary *dict = @{@"url":fileName};
        [imageNameArray addObject:dict];
        NSString *urlStr =[NSString stringWithFormat:@"http://%@:%zd/imconsole/mobileFile_fileUpload.action?userName=%@&password=%@&companyId=%@&type=%@&filename=%@&userId=%@&from=ios&uploadType=circle", serverSetting.IMIp, serverSetting.IMPort, @"admin", paddword, M_STOREVALUE(serverSetting.companyId), @"image", fileName, contact.UserID];
        NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
        NSMutableURLRequest *request = [serializer multipartFormRequestWithMethod:@"POST" URLString:requestUrl parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
            [formData appendPartWithFileData:imgData name:fileName fileName:fileName mimeType:@"image"];
        } error:nil];
        AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
        operation.responseSerializer = [AFJSONResponseSerializer serializer];
        
        [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
            if (![responseObject[@"result"] isEqualToString:@"success"]) {
                noError = NO;
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            noError = NO;
        }];
        [operationArray addObject:operation];
    }
    if (data.length>0) {
        NSString *videoName = [NSString stringWithFormat:@"%@___%@.mp4",contact.UserID,timeStamp];
        NSDictionary *dict = @{@"video":videoName,@"length":@(data.length)};
        [videoNameArray addObject:dict];
        NSString *urlStr =[NSString stringWithFormat:@"http://%@:%zd/imconsole/mobileFile_fileUpload.action?userName=%@&password=%@&companyId=%@&type=%@&filename=%@&userId=%@&from=ios", serverSetting.IMIp, serverSetting.IMPort, @"admin", paddword, M_STOREVALUE(serverSetting.companyId), @"video", videoName, contact.UserID];
        NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
        NSMutableURLRequest *request = [serializer multipartFormRequestWithMethod:@"POST" URLString:requestUrl parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
            [formData appendPartWithFileData:data name:fileName fileName:fileName mimeType:@"image"];
        } error:nil];
        AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
        operation.responseSerializer = [AFJSONResponseSerializer serializer];
        
        [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
            if (![responseObject[@"result"] isEqualToString:@"success"]) {
                noError = NO;
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            noError = NO;
        }];
        [operationArray addObject:operation];
    }
    
    NSDictionary *dict1 = @{@"companyId":M_STOREVALUE(serverSetting.companyId),@"userName":M_STOREVALUE(contact.UserName),@"userId":M_STOREVALUE(contact.UserID),@"type":type,@"content":M_STOREVALUE(content),@"imageName":imageNameArray,@"videoName":videoNameArray,@"visibleUserId":M_STOREVALUE(visibleUseId) ,@"id":@(shareId.longLongValue)};
    NSString *str1 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict1 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    NSDictionary *dict2 = @{@"key":@"efeng",@"text":str1};
    NSString *str2 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict2 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    
    
    NSString *urlStr = [NSString stringWithFormat:@"http://%@:%zd/imconsole/circleContent_addReleaseContent.action?param=%@", M_STOREVALUE(serverSetting.IMIp),serverSetting.IMPort,[self getDesAndBase64WithString:str2]];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    //    operation.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/json"];
    
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (noError) {
            successHandle(operation,responseObject);
        }
        else
        {
            [USER_DEFAULT setBool:YES forKey:@"sendOK"];
            [USER_DEFAULT synchronize];
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [USER_DEFAULT setBool:YES forKey:@"sendOK"];
        [USER_DEFAULT synchronize];
        failureHandle(operation,error);
        
    }];
    
    for (int i = 0; i < operationArray.count; i ++) {
        AFHTTPRequestOperation *op = operationArray[i];
        [operation addDependency:op];
        [_queen addOperation:op];
    }
    [_queen addOperation:operation];
}

- (void)uploadGroupWithContentData:(NSData *)contentData fileNmae:(NSString *)fileName groupId:(NSString *)groupId dataType:(NSString *)dataType fileType:(NSString *)fileType successHandel:(void (^)(NSURLSessionDataTask *, id))successHandle filarueHandle:(void (^)(NSURLSessionDataTask *, NSError *))failureHandle progressHandle:(void (^)(NSURLSession *, NSURLSessionTask *, int64_t, int64_t, int64_t))processHandle
{
    
    if (contentData == nil) {
        return;
    }
    //文件大小3
    NSInteger len = [contentData length];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    NetAndAudioModel *netAndAudio = [[NetAndAudioModel alloc] init];
    netAndAudio.manager = manager;
    netAndAudio.serFileName = fileName;
    [self.operationArray addObject:netAndAudio];
    
    [manager setTaskDidSendBodyDataBlock:^(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
        
    }];
    
//    CServerSettingMgr *serverMgr = [[CServerSettingMgr alloc] init];
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSString *localServerAddr = serverSetting.IMIp;
    NSInteger openFirePort = serverSetting.IMPort;
    NSString *userName = @"admin";
    
    NSRange range ;
    range.location = 8;
    range.length = 16;
    NSString *paddword = [[@"88888888" stringFromMD5] substringWithRange:range];
    //    NSString *paddword = [@"88888888" stringFromMD5] ;
    
    //bug 8715 fixed by lixu
    NSString *urlStr =[NSString stringWithFormat:@"http://%@:%zd/imconsole/mobileFile_shareFileUpload.action?userName=%@&password=%@&companyId=%@&filename=%@&type=%@&groupId=%@&from=ios&fileSize=%ld", localServerAddr, openFirePort, userName, paddword,M_STOREVALUE(serverSetting.companyId), fileName,dataType, groupId,(long)len];
   NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [manager POST:requestUrl parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFileData:contentData name:fileName fileName:fileName mimeType:fileType];
    } success:^(NSURLSessionDataTask *task, id responseObject) {
        successHandle(task, responseObject);
         [self.operationArray removeObject:netAndAudio];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failureHandle(task, error);
         [self.operationArray removeObject:netAndAudio];
    }];

}
- (void)downLoadWithVideoUrl:(NSString*)url ssuccessHandel:(void (^)(AFHTTPRequestOperation *operation, id responseObject))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failureHandle progressHandle:(void (^)(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead))processHandle filePath:(NSString *)filePath
{
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    
    NSString * requestUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFHTTPResponseSerializer serializer];
    operation.outputStream = [NSOutputStream outputStreamToFileAtPath:filePath append:YES];
    [operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
        processHandle(bytesRead, totalBytesRead, totalBytesExpectedToRead);
    }];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failureHandle(operation, error);
    }];
    [_queen addOperation:operation];
    
}

//- (void)uploadShareImageWith fileNmae:(NSString *)fileName groupId:(NSString *)groupId dataType:(NSString *)dataType fileType:(NSString *)fileType messageIndex:(int64_t)messageIndex successHandel:(void (^)(NSURLSessionDataTask *, id))successHandle filarueHandle:(void (^)(NSURLSessionDataTask *, NSError *))failureHandle progressHandle:(void (^)(NSURLSession *, NSURLSessionTask *, int64_t, int64_t, int64_t))processHandle
//{
//    
//    if (contentData == nil) {
//        return;
//    }
//    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
//    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
//    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
//    
//    NetAndAudioModel *netAndAudio = [[NetAndAudioModel alloc] init];
//    netAndAudio.manager = manager;
//    netAndAudio.serFileName = fileName;
//    [self.operationArray addObject:netAndAudio];
//    
//    [manager setTaskDidSendBodyDataBlock:^(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
//        
//    }];
//    
//    //    CServerSettingMgr *serverMgr = [[CServerSettingMgr alloc] init];
//    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
//    NSString *localServerAddr = serverSetting.IMIp;
//    NSInteger openFirePort = serverSetting.IMPort;
//    NSString *userName = @"admin";
//    
//    NSRange range ;
//    range.location = 8;
//    range.length = 16;
//    NSString *paddword = [[@"88888888" stringFromMD5] substringWithRange:range];
//    //    NSString *paddword = [@"88888888" stringFromMD5] ;
//    
//    
//    NSString *urlStr =[NSString stringWithFormat:@"http://%@:%zd/imconsole/mobileFile_shareFileUpload.action?userName=%@&password=%@&companyId=%@&filename=%@&type=%@&groupId=%@&from=ios", localServerAddr, openFirePort, userName, paddword,M_STOREVALUE(serverSetting.companyId), fileName,dataType, groupId];
//    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//    [manager POST:requestUrl parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
//        [formData appendPartWithFileData:contentData name:fileName fileName:fileName mimeType:fileType];
//    } success:^(NSURLSessionDataTask *task, id responseObject) {
//        successHandle(task, responseObject);
//        [self.operationArray removeObject:netAndAudio];
//    } failure:^(NSURLSessionDataTask *task, NSError *error) {
//        failureHandle(task, error);
//        [self.operationArray removeObject:netAndAudio];
//    }];
//    
//}
//

- (void)downLoadeWithFileNmae:(NSString *)fileName userId:(NSString *)userId dataType:(NSString *)dataType ssuccessHandel:(void (^)(AFHTTPRequestOperation *operation, id responseObject))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failureHandle progressHandle:(void (^)(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead))processHandle dataLenth:(NSString *)dataLenth filePath:(NSString *)filePath
{
    
    if (fileName != nil && dataLenth != nil) {
        if ([dataType isEqualToString:@"file"]) {
            CFileModel *filemodel = nil;
            filemodel = [self.downMgr loadFileWihtServerFileName:fileName];
            if (filemodel) {
                
            } else {
                filemodel = [[CFileModel alloc] init];
                filemodel.FileSize = dataLenth.longLongValue;
                filemodel.serverFileName = fileName;
                [self.downMgr insertDownloadFile:filemodel];
            }
        }
    }
//    CServerSettingMgr *serverMgr = [[CServerSettingMgr alloc] init];
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSString *localServerAddr = serverSetting.IMIp;
    NSInteger openFirePort = serverSetting.IMPort;
    NSString *userName = @"admin";
    NSRange range ;
    range.location = 8;
    range.length = 16;
    
    NSString *companyId = nil;
    CContactModel *contact = [[[CContactMgr alloc] init] loadContactWithUserId:userId];
    
    companyId = contact.compCode;
    NSString *paddword = [[@"88888888" stringFromMD5] substringWithRange:range];
    
    
    
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
   
     __block AFHTTPRequestOperation *operation3;
    NSData *data = [NSData dataWithContentsOfFile:filePath];
    
    NSString *urlStr =[NSString stringWithFormat:@"http://%@:%zd/imconsole/mobileFile_download.action?userName=%@&password=%@&companyId=%@&type=%@&filename=%@&userId=%@&sysType=ios", localServerAddr, openFirePort, userName, paddword,M_STOREVALUE(companyId), dataType, fileName, userId];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    //bug 9457 fixed by lixu
//    NSRange range1 = [requestUrl rangeOfString:@"+"];
//    if (range1.location != NSNotFound) {
//        requestUrl = [requestUrl stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"];
//    }
//    NSRange range2 = [requestUrl rangeOfString:@"%20"];
//    if (range2.location != NSNotFound) {
//        requestUrl = [requestUrl stringByReplacingOccurrencesOfString:@"%20" withString:@"+"];
//    }
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    [request setValue:[NSString stringWithFormat:@"bytes=%zd-%zd",data.length,dataLenth.integerValue] forHTTPHeaderField:@"Range"];
    NSMutableURLRequest *mutableURLRequest = [request mutableCopy];
    request = mutableURLRequest;
    operation3 = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation3.responseSerializer = [AFHTTPResponseSerializer serializer];
//    self.operation = operation3;
    NetAndAudioModel *netAndAudio = [[NetAndAudioModel alloc] init];
    netAndAudio.operation = operation3;
    netAndAudio.serFileName = fileName;
     operation3.outputStream = [NSOutputStream outputStreamToFileAtPath:filePath append:YES];
    [self.operationArray addObject:netAndAudio];
    [operation3 setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
        
        processHandle(bytesRead, totalBytesRead, totalBytesExpectedToRead);
        netAndAudio.downPresValue = data.length / dataLenth.floatValue;
    }];
    [operation3 setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        successHandle(operation,responseObject);
        
        [self.operationArray removeObject:netAndAudio];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failureHandle(operation, error);
        [self.operationArray removeObject:netAndAudio];
    }];
    
    [_queen addOperation:operation3];
}

- (void)downLoadeGroupWithFileNmae:(NSString *)fileName GroupId:(NSString *)GroupId dataType:(NSString *)dataType successHandel:(void (^)(AFHTTPRequestOperation *operation, id responseObject))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failureHandle progressHandle:(void (^)(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead))processHandle dataLenth:(NSString *)dataLenth filePath:(NSString *)filePath
{

    
    if ([dataType isEqualToString:@"file"]) {
        CFileModel *filemodel = nil;
        filemodel = [self.downMgr loadFileWihtServerFileName:fileName];
        if (filemodel) {
            
        } else {
            filemodel = [[CFileModel alloc] init];
            filemodel.FileSize = dataLenth.longLongValue;
            filemodel.serverFileName = fileName;
            [self.downMgr insertDownloadFile:filemodel];
        }
    }
//    CServerSettingMgr *serverMgr = [[CServerSettingMgr alloc] init];
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSString *localServerAddr = serverSetting.IMIp;
    NSInteger openFirePort = serverSetting.IMPort;
    NSString *userName = @"admin";
    NSRange range ;
    range.location = 8;
    range.length = 16;
    NSString *paddword = [[@"88888888" stringFromMD5] substringWithRange:range];
    
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    
//    NSString *requestUrl1 = [NSString stringWithFormat:@"http://%@:%zd/imconsole/mobileFile_srvFileSize.action?userName=%@&password=%@&companyId=%@&srvType=shareFile&groupId=%@&filename=%@&type=%@", localServerAddr, openFirePort, userName, paddword,M_STOREVALUE(serverSetting.companyId), GroupId, fileName,dataType];
//    NSMutableURLRequest *request1 = [serializer requestWithMethod:@"GET" URLString:requestUrl1 parameters:nil error:nil];
//    NSMutableURLRequest *mutableURLRequest1 = [request1 mutableCopy];
//    request1 = mutableURLRequest1;
//    
//    __block NSInteger fileSIze = 0;
   

//    AFHTTPRequestOperation *operation1 = [[AFHTTPRequestOperation alloc] initWithRequest:request1];
//    operation1.responseSerializer = [AFHTTPResponseSerializer serializer];
//    [operation1 setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
//        
//        
//        id result = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
//        fileSIze = [[result objectForKey:@"fileSize"] integerValue];
//      
//        //
//    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//        
//         failureHandle(operation, error);
//    }];
//    
//       [_queen addOperation:operation1];

      NSData *data = [NSData dataWithContentsOfFile:filePath];
     __block AFHTTPRequestOperation *operation3;
    NSString *urlStr =[NSString stringWithFormat:@"http://%@:%zd/imconsole/mobileFile_shareDownload.action?userName=%@&password=%@&companyId=%@&type=%@&filename=%@&groupId=%@", localServerAddr, openFirePort, userName, paddword,M_STOREVALUE(serverSetting.companyId),dataType, fileName, GroupId];
    
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    //bug 9547 fiexed by lixu
    NSRange range1 = [requestUrl rangeOfString:@"+"];
    if (range1.location != NSNotFound) {
        requestUrl = [requestUrl stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"];
    }
    NSRange range2 = [requestUrl rangeOfString:@"%20"];
    if (range2.location != NSNotFound) {
        requestUrl = [requestUrl stringByReplacingOccurrencesOfString:@"%20" withString:@"+"];
    }

    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    
    [request setValue:[NSString stringWithFormat:@"bytes=%zd-%zd",data.length,dataLenth.integerValue] forHTTPHeaderField:@"Range"];
    NSMutableURLRequest *mutableURLRequest = [request mutableCopy];
    request = mutableURLRequest;
    operation3 = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation3.responseSerializer = [AFHTTPResponseSerializer serializer];
//    self.operation = operation3;
    operation3.outputStream = [NSOutputStream outputStreamToFileAtPath:filePath append:YES];
    
    
    NetAndAudioModel *netAndAudio = [[NetAndAudioModel alloc] init];
    netAndAudio.operation = operation3;
    netAndAudio.serFileName = fileName;
    [self.operationArray addObject:netAndAudio];
    
    [operation3 setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
        
        processHandle(bytesRead, totalBytesRead, totalBytesExpectedToRead);
        
    }];
    [operation3 setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        successHandle(operation,responseObject);
        [self.operationArray removeObject:netAndAudio];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failureHandle(operation, error);
        [self.operationArray removeObject:netAndAudio];
    }];
    
    [_queen addOperation:operation3];
}
//删除群文件
-(void)deleteGroupFileWithFileName:(NSString*)fileName GroupId:(NSString*)GroupId dataType:(NSString *)dataType successHandel:(void (^)(AFHTTPRequestOperation *operation, id responseObject))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failureHandle
{
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSString *localServerAddr = serverSetting.IMIp;
    NSInteger openFirePort = serverSetting.IMPort;
    NSString *userName = @"admin";
    NSRange range ;
    range.location = 8;
    range.length = 16;
    NSString *paddword = [[@"88888888" stringFromMD5] substringWithRange:range];
    NSString *urlStr =[NSString stringWithFormat:@"http://%@:%zd/imconsole/mobileFile_shareFileDelete.action?userName=%@&password=%@&companyId=%@&filename=%@&groupId=%@&type=%@", localServerAddr, openFirePort, userName, paddword,M_STOREVALUE(serverSetting.companyId),fileName,GroupId,dataType];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureHandle(operation,error);
        
        
    }];
    [_queen addOperation:operation];
}

-(void)UploadHeadFileWithImageData:(NSData *)imageData userId:(NSString *)userId userCode:userCode successHandel:(void (^)(NSURLSessionDataTask *, id))successHandle filarueHandle:(void (^)(NSURLSessionDataTask *, NSError *))failureHandle progressHandle:(void (^)(NSURLSession *, NSURLSessionTask *, int64_t, int64_t, int64_t))processHandle
{
   
//    CServerSettingMgr *serverMgr = [[CServerSettingMgr alloc] init];
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSString *localServerAddr = serverSetting.IMIp;
    NSInteger openFirePort = serverSetting.IMPort;
    NSString *userName = @"admin";
    
    
    NSRange range ;
    range.location = 8;
    range.length = 16;
    NSString *paddword = [[@"88888888" stringFromMD5] substringWithRange:range];
    //    NSString *paddword = [@"88888888" stringFromMD5] ;
    NSString *fileName = [NSString stringWithFormat:@"%@.png", userId];
    
    NSString *urlStr =[NSString stringWithFormat:@"http://%@:%zd/imconsole/mobileFile_uploadHeadImg.action?userName=%@&password=%@&companyId=%@&userId=%@&fileLength=%zd&filename=%@&userCode=%@&sysType=ios", localServerAddr, openFirePort, userName, paddword,serverSetting.companyId, userId, imageData.length, fileName, userCode];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager setTaskDidSendBodyDataBlock:^(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
       processHandle(session, task,bytesSent,totalBytesSent,totalBytesExpectedToSend);
    }];
    
    [manager POST:requestUrl  parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFileData:imageData name:@"testHeader.png" fileName:@"testHeader.png" mimeType:@"img/png"];
    } success:^(NSURLSessionDataTask *task, id responseObject) {
         successHandle(task, responseObject);
       
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
       failureHandle(task, error);
    }];
    
}

- (NSString *)UploadHeadFileWithUserId:(NSString *)userId
{
//    CServerSettingMgr *serverMgr = [[CServerSettingMgr alloc] init];
//    CServerSettingModel *serverSetting = [serverMgr getSetting];
//    NSString *localServerAddr = serverSetting.IMIp;
//    NSInteger openFirePort = serverSetting.IMPort;
//    NSString *userName = @"admin";
//    
//    NSRange range ;
//    range.location = 8;
//    range.length = 16;
//    NSString *paddword = [[@"88888888" stringFromMD5] substringWithRange:range];
//    //    NSString *paddword = [@"88888888" stringFromMD5] ;
//    NSString *fileName = [NSString stringWithFormat:@"%@.png", userId];
//    
////    NSString *requestUrl =[NSString stringWithFormat:@"http://%@:%zd/imconsole/mobileFile_uploadHeadImg.action?userName=%@&password=%@&companyId=%@&userId=%@&fileLength=%zd&filename=%@&userCode=%@&sysType=ios", localServerAddr, openFirePort, userName, paddword, userId, fileName];
    
    return nil;
}

- (NSString *)DownHeadFileWithContact:(NSString *)userId
{
//    CServerSettingMgr *serverMgr = [[CServerSettingMgr alloc] init];
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSString *localServerAddr = serverSetting.IMIp;
    NSInteger openFirePort = serverSetting.IMPort;
    NSString *userName = @"admin";
    
    NSRange range ;
    range.location = 8;
    range.length = 16;
    NSString *paddword = [[@"88888888" stringFromMD5] substringWithRange:range];
    //    NSString *paddword = [@"88888888" stringFromMD5] ;
    NSString *fileName = [NSString stringWithFormat:@"%@.png", userId];
    
    NSString *urlStr =[NSString stringWithFormat:@"http://%@:%zd/imconsole/mobileFile_downloadHeadImg.action?userName=%@&password=%@&companyId=%@&userId=%@&filename=%@", localServerAddr, openFirePort, userName, paddword,serverSetting.companyId, userId, fileName];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//     NSLog(@"%@",requestUrl);
    return requestUrl;
}

-(void)DownHeadFile
{
//    CServerSettingMgr *serverMgr = [[CServerSettingMgr alloc] init];
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSString *localServerAddr = serverSetting.IMIp;
    NSInteger openFirePort = serverSetting.IMPort;
    NSString *userName = @"admin";
    NSRange range ;
    range.location = 8;
    range.length = 16;
    NSString *paddword = [[@"88888888" stringFromMD5] substringWithRange:range];
    //    NSString *paddword = [@"88888888" stringFromMD5] ;
    NSString *userId = @"ff8080814db3a2bc014db75fde070001";
    NSString *fileName = [NSString stringWithFormat:@"%@_141414141414.png", userId];
    
    NSString *urlStr =[NSString stringWithFormat:@"http://%@:%zd/imconsole/mobileFile_downloadHeadImg.action?userName=%@&password=%@&userId=%@&filename=%@", localServerAddr, openFirePort, userName, paddword, userId, fileName];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    [request setValue:@"bytes=0-" forHTTPHeaderField:@"Range"];
    NSMutableURLRequest *mutableURLRequest = [request mutableCopy];
    request = mutableURLRequest;
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    [operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
        
//        NSLog(@"bytesRead:%u, totalBytesRead:%lld totalBytesExpectedToRead:%lld", bytesRead, totalBytesRead, totalBytesExpectedToRead);
        
    }];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
        [responseObject writeToFile:[NSString stringWithFormat:@"%@/%@", path, @"javaios.txt"] atomically:NO];
        
//        NSLog(@"success");
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//        NSLog(@"failed!");
        
    }];
    [_queen addOperation:operation];
    
}

-(void)getContacts
{
    
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"recentcontactuser"];
    //    DDXMLNode *node =[DDXMLNode elementWithName:@"query"];
    //    NSXMLElement *query = [iq elementForName:@"query" xmlns:XMPPMUCAdminNamespace];
    //    DDXMLNode *node =[DDXMLNode elementWithName:@"query" children:@[@"xmlns"] attributes:@[@"1233"]];
    //    [aIQ addChild:node];
    
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:recentcontactuser"];
    
    [aIQ addChild:[DDXMLNode elementWithName:@"query" children:nil attributes:[NSArray arrayWithObjects:attrs, nil]]];
    
    [[CXmppMgr shareInstance] sendElement:aIQ];
    
    
    
    
    
}

- (void)getUserIdByUserCode:(NSString *)userCode
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"getUserIdByUserCode"];
    
    
    DDXMLNode *child = [DDXMLNode elementWithName:@"userCode" stringValue:userCode];
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:getUserIdByUserCode"];
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:child, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    [[CXmppMgr shareInstance] sendElement:aIQ];

}
-(void)getContactGroups
{
    
    
    
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"console17b158c3"];
    
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:recentcontactgroup"];
    
    [aIQ addChild:[DDXMLNode elementWithName:@"query" children:nil attributes:[NSArray arrayWithObjects:attrs, nil]]];
    
    [[CXmppMgr shareInstance] sendElement:aIQ];
    
}

-(void)getUserGroup
{
    
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"recentusergroup"];
    
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:recentusergroup"];
    
    [aIQ addChild:[DDXMLNode elementWithName:@"query" children:nil attributes:[NSArray arrayWithObjects:attrs, nil]]];
    
    [[CXmppMgr shareInstance] sendElement:aIQ];
    
}

- (void)getUserSettingInfo
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"appmsgNoticeSetGet"];
    
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:appmsgNoticeSetGet"];
    
    [aIQ addChild:[DDXMLNode elementWithName:@"query" children:nil attributes:[NSArray arrayWithObjects:attrs, nil]]];
    
    [[CXmppMgr shareInstance] sendElement:aIQ];

}

- (void)SetUserSettingInfoWithSettingStr:(NSString *)settingStr
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"appmsgNoticeSetSet"];
    
    
    DDXMLNode *child = [DDXMLNode elementWithName:@"msgNoticeSetSet" stringValue:settingStr];
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:appmsgNoticeSetSet"];
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:child, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    [[CXmppMgr shareInstance] sendElement:aIQ];
    

}
-(void)getGroupListWithUserId:(NSString *)userId
{
    
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"groupListForUser"];
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:groupListForUser"];
    DDXMLNode *child1 =[DDXMLNode elementWithName:@"userId" stringValue:userId];
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:child1, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    
    
    
    [[CXmppMgr shareInstance] sendElement:aIQ];
    [USER_DEFAULT setBool:NO forKey:isGroupCompleted];
    [USER_DEFAULT synchronize];

}


-(void)addGroup
{
    
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"discussiongroupcreate"];
    
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:discussiongroupcreate"];
    DDXMLNode *attrs1 =[DDXMLNode attributeWithName:@"groupname" stringValue:@"群名称1"];
    DDXMLNode *attrs2 =[DDXMLNode attributeWithName:@"groupintroduction" stringValue:@"测试群 简介1"];
    DDXMLNode *attrs3 =[DDXMLNode attributeWithName:@"groupnotice" stringValue:@"测试群公告1"];
    DDXMLNode *child1 = [DDXMLNode elementWithName:@"group" children:nil attributes:[NSArray arrayWithObjects:attrs1,attrs2, attrs3,nil] ];
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:child1, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    
    
    [[CXmppMgr shareInstance] sendElement:aIQ];
}

-(void)addMemberToGroup
{
    
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"discussiongroupcremem"];
    
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:discussiongroupcremem"];
    DDXMLNode *attrs1 =[DDXMLNode attributeWithName:@"groupcode" stringValue:@"fe37e9871fb0b1ae202a7dab73d957ec"];
    //    DDXMLNode *attrs2 =[DDXMLNode attributeWithName:@"groupintroduction" stringValue:@"测试群 简介1"];
    //    DDXMLNode *attrs3 =[DDXMLNode attributeWithName:@"groupnotice" stringValue:@"测试群公告1"];
    DDXMLNode *child1 = [DDXMLNode elementWithName:@"group" children:nil attributes:[NSArray arrayWithObjects:attrs1,nil] ];
    NSString *localServerAddr = [USER_DEFAULT objectForKey:M_SERVERADDR];
    DDXMLNode *attrs2 =[DDXMLNode attributeWithName:@"name" stringValue:[NSString stringWithFormat:@"lyt3@%@;lyt1@%@;lyt2@%@;lyt4@%@", localServerAddr, localServerAddr,localServerAddr,localServerAddr]];
    //    DDXMLNode *attrs2 =[DDXMLNode attributeWithName:@"groupintroduction" stringValue:@"测试群 简介1"];
    //    DDXMLNode *attrs3 =[DDXMLNode attributeWithName:@"groupnotice" stringValue:@"测试群公告1"];
    DDXMLNode *child2 = [DDXMLNode elementWithName:@"members" children:nil attributes:[NSArray arrayWithObjects:attrs2,nil] ];
    
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:child1, child2, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    
    
    
    [[CXmppMgr shareInstance] sendElement:aIQ];
    
    
}


-(void)getGroupInfo
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"groupProperty"];
    
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:groupProperty"];
    DDXMLNode *attrs1 =[DDXMLNode attributeWithName:@"groupId" stringValue:@"fe37e9871fb0b1ae202a7dab73d957ec"];
    DDXMLNode *child1 = [DDXMLNode elementWithName:@"parameter" children:nil attributes:[NSArray arrayWithObjects:attrs1, nil] ];
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:child1, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    
    
    
    [[CXmppMgr shareInstance] sendElement:aIQ];
    
}


-(void)getGroupMembersWithGroup:(CGroupModel *)Group
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"GroupUserList"];
//74e5c1f537d5e28e626b45e5bda31008
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:GroupUserList"];
//    [attrs setName:GroupId];
    DDXMLNode *attrs1 =[DDXMLNode elementWithName:@"groupId" stringValue:Group.GroupId];
    DDXMLNode *attrs2 = [DDXMLNode elementWithName:@"type" stringValue:[NSString stringWithFormat:@"%zd",Group.groupType]];
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:attrs1,attrs2, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    
    
    [[CXmppMgr shareInstance] sendElement:aIQ];
    
}

//----------------------------


-(void)delMemberFromGroup
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"discussiongroupdelmem"];
    
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:discussiongroupdelmem"];
    DDXMLNode *attrs1 =[DDXMLNode attributeWithName:@"groupcode" stringValue:@"fe37e987169a3cb636b3850c0ab6b7de"];
    //    DDXMLNode *attrs2 =[DDXMLNode attributeWithName:@"groupintroduction" stringValue:@"测试群 简介1"];
    //    DDXMLNode *attrs3 =[DDXMLNode attributeWithName:@"groupnotice" stringValue:@"测试群公告1"];
    DDXMLNode *child1 = [DDXMLNode elementWithName:@"group" children:nil attributes:[NSArray arrayWithObjects:attrs1,nil] ];
    NSString *localServerAddr = [USER_DEFAULT objectForKey:M_SERVERADDR];
    DDXMLNode *attrs2 =[DDXMLNode attributeWithName:@"name" stringValue:[NSString stringWithFormat:@"lyt4@%@", localServerAddr]];
    //    DDXMLNode *attrs2 =[DDXMLNode attributeWithName:@"groupintroduction" stringValue:@"测试群 简介1"];
    //    DDXMLNode *attrs3 =[DDXMLNode attributeWithName:@"groupnotice" stringValue:@"测试群公告1"];
    DDXMLNode *child2 = [DDXMLNode elementWithName:@"members" children:nil attributes:[NSArray arrayWithObjects:attrs2,nil] ];
    
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:child1, child2, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    
    
    
    [[CXmppMgr shareInstance] sendElement:aIQ];
    
}


-(void)updateGroupInfo
{

    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"discussiongroupupdate"];
    
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:discussiongroupupdate"];
    DDXMLNode *attrs1 =[DDXMLNode attributeWithName:@"groupname" stringValue:@"群名称2"];
    DDXMLNode *attrs2 =[DDXMLNode attributeWithName:@"groupintroduction" stringValue:@"测试群 简介2"];
    DDXMLNode *attrs3 =[DDXMLNode attributeWithName:@"groupnotice" stringValue:@"测试群公告2"];
    DDXMLNode *attrs4 =[DDXMLNode attributeWithName:@"groupcode" stringValue:@"fe37e987169a3cb636b3850c0ab6b7de"];
    DDXMLNode *child1 = [DDXMLNode elementWithName:@"group" children:nil attributes:[NSArray arrayWithObjects:attrs1,attrs2, attrs3,attrs4,nil] ];
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:child1, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    [[CXmppMgr shareInstance] sendElement:aIQ];
}

-(void)updateSingleUserInfoWithDic:(NSDictionary *)dic
{
    
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"userinfomodify"];
    
    
    NSMutableArray *array = [NSMutableArray array];
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:userinfomodify"];
    [dic enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *obj, BOOL *stop) {
       DDXMLNode *attrs1 =[DDXMLNode attributeWithName:key stringValue:obj];
        [array addObject:attrs1];
    }];
    
    
    DDXMLNode *attrs2 = [DDXMLNode attributeWithName:@"companyId" stringValue:[[CFolderMgr shareInstance].serSettingMgr getSetting].companyId];
    [array addObject:attrs2];
    DDXMLNode *child1 = [DDXMLNode elementWithName:@"userinfo" children:nil attributes:array];
    DDXMLElement *queryElm =  [DDXMLElement elementWithName:@"query" children:[NSArray arrayWithObjects:child1, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:queryElm];
    [[CXmppMgr shareInstance] sendElement:aIQ];
    
    
}
-(void)updateSignatureWithAurograph:(NSString *)personAutograph AndCompanyId:(NSString *)companyId
{
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:personAutograph"];
    DDXMLNode *attrs1 =[DDXMLNode attributeWithName:@"autograph" stringValue:personAutograph];
    DDXMLNode *attrs2 =[DDXMLNode attributeWithName:@"companyId" stringValue:companyId];
    DDXMLNode *child1 = [DDXMLNode elementWithName:@"personAutograph" children:nil attributes:[NSArray arrayWithObjects: attrs1,attrs2,nil] ];
    DDXMLElement *queryElm =  [DDXMLElement elementWithName:@"query" children:[NSArray arrayWithObjects:child1, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"personAutograph"];
    
    
    [aIQ addChild:queryElm];
    [[CXmppMgr shareInstance] sendElement: aIQ];
}

-(void)updatePasswordWithStr:(NSString *)str
{
    //    XMPPIQ *aIQ;
    //    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"console17b158c3"];
    
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:changepassword"];
    DDXMLNode *attrs1 =[DDXMLNode attributeWithName:@"password" stringValue:str];
    DDXMLNode *child1 = [DDXMLNode elementWithName:@"changepassword" children:nil attributes:[NSArray arrayWithObjects: attrs1,nil] ];
    DDXMLElement *queryElm =  [DDXMLElement elementWithName:@"query" children:[NSArray arrayWithObjects:child1, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    //    [[CXmppMgr shareInstance] sendElement: queryElm];
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"changepassword"];
    
    
    [aIQ addChild:queryElm];
    [[CXmppMgr shareInstance] sendElement: aIQ];
}


-(void)getUserRightList
{
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:userrightlist"];
    DDXMLElement *queryElm =  [DDXMLElement elementWithName:@"query" children:nil attributes:[NSArray arrayWithObjects:attrs, nil]];
    //    [[CXmppMgr shareInstance] sendElement: queryElm];
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"userrightlist"];
    
    
    [aIQ addChild:queryElm];
    [[CXmppMgr shareInstance] sendElement: aIQ];
}
-(void)getDeptUserTreeWith:(NSString *)choose
{
    CServerSettingModel *model = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:deptUserTreeJson"];
    DDXMLNode *child =[DDXMLNode elementWithName:@"companyId" stringValue:model.companyId];
    DDXMLNode *child1 = [DDXMLNode elementWithName:@"方式" stringValue:choose];
    DDXMLElement *queryElm =  [DDXMLElement elementWithName:@"query" children:[NSArray arrayWithObjects:child,child1, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    //    [[CXmppMgr shareInstance] sendElement: queryElm];
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"deptUserTreeJson"];
    
    
    [aIQ addChild:queryElm];
    [[CXmppMgr shareInstance] sendElement: aIQ];
    [USER_DEFAULT setBool:NO forKey:isContactCompleted];
    [USER_DEFAULT synchronize];
}
-(void)getDeptUserTree
{
    CServerSettingModel *model = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:deptUserTreeJson"];
    DDXMLNode *child =[DDXMLNode elementWithName:@"companyId" stringValue:model.companyId];
    DDXMLElement *queryElm =  [DDXMLElement elementWithName:@"query" children:[NSArray arrayWithObjects:child, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    //    [[CXmppMgr shareInstance] sendElement: queryElm];
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"deptUserTreeJson"];
    
    
    [aIQ addChild:queryElm];
    [[CXmppMgr shareInstance] sendElement: aIQ];
    [USER_DEFAULT setBool:NO forKey:isContactCompleted];
    [USER_DEFAULT synchronize];
    
}

-(void)delGroup
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"discussiongroupdel"];
    
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:discussiongroupdel"];
    DDXMLNode *attrs1 =[DDXMLNode attributeWithName:@"groupcode" stringValue:@"fe37e987169a3cb636b3850c0ab6b7de"];
    DDXMLNode *attrs2 =[DDXMLNode attributeWithName:@"groupname" stringValue:@"群名称2"];
    DDXMLNode *child1 = [DDXMLNode elementWithName:@"group" children:nil attributes:[NSArray arrayWithObjects:attrs1,attrs2,nil] ];
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:child1, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    [[CXmppMgr shareInstance] sendElement:aIQ];
}

-(void)getUserInfoWithUserId:(NSString *)userIds
{
    
    if (M_ISSTRNULL(userIds)) {
        return;
    }
    
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"userdetails"];
    
    
    
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:userdetails"];
//    DDXMLNode *attrs1 =[DDXMLNode attributeWithName:@"userId" stringValue:@"lyt1"];
    DDXMLNode *child1 = [DDXMLNode elementWithName:@"userIds" stringValue:userIds];
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:child1, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    
    
    
    [[CXmppMgr shareInstance] sendElement:aIQ];
    
}




- (void)getCurUserIdWithUserCode:(NSString *)userCode
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"getUserIdByUserCode"];
    
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:getUserIdByUserCode"];
    DDXMLNode *child1 = [DDXMLNode elementWithName:@"userCode" stringValue:userCode];
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:child1, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    
    
    
    [[CXmppMgr shareInstance] sendElement:aIQ];

}

- (void)getCompanyPrensences
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"getcompanypresences"];
    
    
    
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:getcompanypresences"];
    //    DDXMLNode *attrs1 =[DDXMLNode attributeWithName:@"userId" stringValue:@"lyt1"];
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:nil attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    
    
    
    [[CXmppMgr shareInstance] sendElement:aIQ];

}
- (void)getOtherUserUpdateInfo:(NSString *)userIds
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"otherUserInfoState"];
    
    CContactModel *curModel = [[[CContactMgr alloc] init] loadCurContact];
   NSString *timestamp = [USER_DEFAULT objectForKey:infoTimeStamp];
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:otherUserInfoState"];
    DDXMLNode *child1 = [DDXMLNode elementWithName:@"timestamp" stringValue:[NSString stringWithFormat:@"%@,%@",curModel.UserID,timestamp]];
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:child1, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    
    
    
    [[CXmppMgr shareInstance] sendElement:aIQ];
    [USER_DEFAULT setBool:NO forKey:isOtherContactCompleted];
    [USER_DEFAULT synchronize];
}

- (void)getServerTime
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"getServerDate"];
    
    
    
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:getServerDate"];
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:nil attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    
    [[CXmppMgr shareInstance] sendElement:aIQ];

}


#pragma mark 用户退出登录以后必须清空 [CFolderMgr shareInstance].recentlyAcc = nil；
- (void)quitLoad
{
//    CServerSettingMgr *serverMgr = [[CServerSettingMgr alloc] init];
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSString *localServerAddr = serverSetting.IMIp;
    NSInteger openFirePort = serverSetting.IMPort;
    NSString *userName = @"admin";
    
    
    NSRange range ;
    range.location = 8;
    range.length = 16;
    NSString *paddword = [[@"88888888" stringFromMD5] substringWithRange:range];
    //    NSString *paddword = [@"88888888" stringFromMD5] ;
    CAccountModel *curAcc = [[CFolderMgr shareInstance].accMgr getRecentlyLoginAccount];
    
    NSString *urlStr =[NSString stringWithFormat:@"http://%@:%zd/imconsole/general_delToken.action?userName=%@&password=%@&userCode=%@", localServerAddr, openFirePort, userName, paddword, curAcc.userName];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager POST:requestUrl parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        [CFolderMgr shareInstance].recentlyAcc = nil;
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        [CFolderMgr shareInstance].recentlyAcc = nil;
    }];
}

- (void)setToken
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"setToken"];
    
    
    NSString *token = [USER_DEFAULT objectForKey:@"KEY_DEVICETOKEN"];
    
    
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:setToken"];
    DDXMLNode *child =[DDXMLNode elementWithName:@"token" stringValue:[NSString stringWithFormat:@"ios,%@",token]];
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:child, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    
    [[CXmppMgr shareInstance] sendElement:aIQ];

}


- (void)getGroupFileListWithGroupId:(NSString *)groupId successHandel:(void (^)(AFHTTPRequestOperation *operation, id responseObject))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failureHandle
{
//    CServerSettingMgr *serverMgr = [[CServerSettingMgr alloc] init];
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSString *localServerAddr = serverSetting.IMIp;
    NSInteger openFirePort = serverSetting.IMPort;
    NSString *userName = @"admin";
    
    
    NSRange range ;
    range.location = 8;
    range.length = 16;
    NSString *paddword = [[@"88888888" stringFromMD5] substringWithRange:range];
    
    
    NSString *urlStr =[NSString stringWithFormat:@"http://%@:%zd/imconsole/mobileFile_shareFileList.action?userName=%@&password=%@&type=file&companyId=%@&groupId=%@", localServerAddr, openFirePort, userName, paddword,serverSetting.companyId,groupId];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
//    operation.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successHandle(operation, responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureHandle(operation, error);
    }];
    [_queen addOperation:operation];


}

- (void)updateMessageReadStatusWithMessageIds:(NSString *)messageIds messageType:(NSString *)messageType
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"returnMessageState"];
    
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:returnMessageState"];
    DDXMLNode *attr1 = [DDXMLNode attributeWithName:@"array" stringValue:messageIds];
    DDXMLNode *attr2 = [DDXMLNode attributeWithName:@"type" stringValue:messageType];
    
    DDXMLNode *child =[DDXMLNode elementWithName:@"messageId" children:nil attributes:[NSArray arrayWithObjects:attr1,attr2, nil]];
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:child, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    [[CXmppMgr shareInstance] sendElement:aIQ];

}

- (void)delOftenContactWithUserId:(NSString *)userId
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"contactDelete"];
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:contactDelete"];
    DDXMLNode *child =[DDXMLNode elementWithName:@"userId" stringValue:[[CFolderMgr shareInstance].accMgr getRecentlyLoginAccount].userId];
    DDXMLNode *child1 =[DDXMLNode elementWithName:@"contactId" stringValue:userId];
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:child,child1, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    
    [[CXmppMgr shareInstance] sendElement:aIQ];
}

- (void)addOftenContactWithUserId:(NSString *)userId
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"contactAdd"];
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:contactAdd"];
    DDXMLNode *child =[DDXMLNode elementWithName:@"userId" stringValue:[[CFolderMgr shareInstance].accMgr getRecentlyLoginAccount].userId];
    DDXMLNode *child1 =[DDXMLNode elementWithName:@"contactId" stringValue:userId];
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:child,child1, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    
    [[CXmppMgr shareInstance] sendElement:aIQ];

}

- (void)getOftenContact
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"contactList"];
    
    
    
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:contactList"];
    DDXMLNode *child =[DDXMLNode elementWithName:@"userId" stringValue:[[CFolderMgr shareInstance].accMgr getRecentlyLoginAccount].userId];
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:child, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    
    [[CXmppMgr shareInstance] sendElement:aIQ];

}

- (void)getCallCenterTelePhoneNumberWithUserId:(NSString *)userId
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"callTelephoneNumber"];
    
    
    
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:callTelephoneNumber"];
    DDXMLNode *child =[DDXMLNode elementWithName:@"userId" stringValue:userId];
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:child, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    
    [[CXmppMgr shareInstance] sendElement:aIQ];

}


//xmppMessage
-(void)sendMessageWithMessage:(NSString *)message messageId:(NSString *)messageId curUser:(CContactModel *)curUser member:(CContactModel *)member group:(CGroupModel *)group
{
    
    XMPPMessage *aMessage;
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    if(member && group == nil)
    {
        aMessage=[XMPPMessage messageWithType:@"chat" to:[XMPPJID jidWithString:[NSString stringWithFormat:@"%@@pcapp.%@",member.UserCode,[[CXmppMgr shareInstance] xmppStream].hostName]]];

        if ([member.UserID isEqualToString:curUser.UserID]) {
            [aMessage addAttributeWithName:@"commonality" stringValue:@"messagePcapp"];
            
        }
        dict[@"toId"] = member.UserID;
        dict[@"toName"] = member.UserName;
    } else if (group && member == nil) {
        if (group.groupType == 1) {
            if (!group.isShow) {
                group.isShow = YES;
                [[CXmppRequestMgr shareInstance] updateDiscussInfoWithGroup:group];
            }
        }
        NSString* roomJid = [NSString stringWithFormat:@"%@@broadcast.%@",group.GroupId,[[CXmppMgr shareInstance] xmppStream].hostName];
        aMessage=[XMPPMessage messageWithType:@"groupchat" to:[XMPPJID jidWithString:roomJid]];
        dict[@"toId"] = group.GroupId;
        dict[@"groupId"] = group.GroupId;
        dict[@"toName"] = group.GroupName;
    }
    
    [aMessage addAttributeWithName:@"from" stringValue:[NSString stringWithFormat:@"%@@%@",curUser.UserCode,[[CXmppMgr shareInstance] xmppStream].hostName]];
    
   
    CServerSettingModel *settingModel = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    dict[@"length"] = @(0);
    dict[@"fromId"] = curUser.UserID;
    dict[@"body"] = message;
    dict[@"fileName"] = @"";
    dict[@"nodeId"] = @"";
    dict[@"status"] = @"";
    dict[@"fromName"] = curUser.UserName;
    dict[@"type"] = @"text";
    dict[@"stream"] = @"";
    dict[@"companyId"] = M_STOREVALUE(settingModel.companyId);
    
     NSString *timeStamp = [UIUtil getCurrentTimeStamp];
    dict[@"sendTime"] = timeStamp;
    
    NSString *idkey = settingModel.yuLiuZiduan1;
    if (M_ISSTRNULL(idkey)) {
        idkey = [self randomChar];
    }

    NSString *relMessageId = nil;
    if (M_ISSTRNULL(messageId)) {
        relMessageId = [NSString stringWithFormat:@"%@%@",timeStamp,idkey];
    } else {
        relMessageId = messageId;
    }

    
    dict[@"messageId"] = relMessageId;
    [aMessage addAttributeWithName:@"id" stringValue:relMessageId];
    if (member && group == nil) {
        if ([member.UserID isEqualToString:curUser.UserID]) {
            dict[@"fromName"] = @"我的手机";
            dict[@"toName"] = @"我的电脑";
        }
        
    }

    
    NSDictionary *dict1 = [NSDictionary dictionaryWithObject:dict forKey:@"messageCommon"];
    NSString *body = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict1 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    [aMessage addChild:[DDXMLNode elementWithName:@"body" stringValue:body]];
    
    [self handleMessage:aMessage curUser:curUser member:member group:group];
    [[CXmppMgr shareInstance] sendElement:aMessage];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"MineDIdSendMessage" object:nil];
    
}
-(void)sendRedPacketMessageWithMessage:(NSString *)message messageId:(NSString *)messageId curUser:(CContactModel *)curUser member:(CContactModel *)member group:(CGroupModel *)group redPacketType:(moneyType)type money:(double)money number:(NSInteger)number successHandel:(void (^)(AFHTTPRequestOperation *, id))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *, NSError *))failureHandle
{
    XMPPMessage *aMessage;
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    if(member && group == nil)
    {
        aMessage=[XMPPMessage messageWithType:@"chat" to:[XMPPJID jidWithString:[NSString stringWithFormat:@"%@@pcapp.%@",member.UserCode,[[CXmppMgr shareInstance] xmppStream].hostName]]];
        
        if ([member.UserID isEqualToString:curUser.UserID]) {
            [aMessage addAttributeWithName:@"commonality" stringValue:@"messagePcapp"];
            
        }
        dict[@"toId"] = member.UserID;
        dict[@"toName"] = member.UserName;
    } else if (group && member == nil) {
        if (group.groupType == 1) {
            if (!group.isShow) {
                group.isShow = YES;
                [[CXmppRequestMgr shareInstance] updateDiscussInfoWithGroup:group];
            }
        }
        NSString* roomJid = [NSString stringWithFormat:@"%@@broadcast.%@",group.GroupId,[[CXmppMgr shareInstance] xmppStream].hostName];
        aMessage=[XMPPMessage messageWithType:@"groupchat" to:[XMPPJID jidWithString:roomJid]];
        dict[@"toId"] = group.GroupId;
        dict[@"groupId"] = group.GroupId;
        dict[@"toName"] = group.GroupName;
    }
    
    [aMessage addAttributeWithName:@"from" stringValue:[NSString stringWithFormat:@"%@@%@",curUser.UserCode,[[CXmppMgr shareInstance] xmppStream].hostName]];
    
    
    CServerSettingModel *settingModel = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    dict[@"length"] = @(0);
    dict[@"fromId"] = curUser.UserID;
    dict[@"body"] = message;
    dict[@"fileName"] = @"";
    dict[@"nodeId"] = @"";
    dict[@"status"] = @"";
    dict[@"fromName"] = curUser.UserName;
    dict[@"type"] = @"redpacket";
    dict[@"stream"] = @"";
    dict[@"companyId"] = M_STOREVALUE(settingModel.companyId);
    
    NSString *timeStamp = [UIUtil getCurrentTimeStamp];
    dict[@"sendTime"] = timeStamp;
    
    NSString *idkey = settingModel.yuLiuZiduan1;
    if (M_ISSTRNULL(idkey)) {
        idkey = [self randomChar];
    }
    
    NSString *relMessageId = nil;
    if (M_ISSTRNULL(messageId)) {
        relMessageId = [NSString stringWithFormat:@"%@%@",timeStamp,idkey];
    } else {
        relMessageId = messageId;
    }
    
    
    dict[@"messageId"] = relMessageId;
    [aMessage addAttributeWithName:@"id" stringValue:relMessageId];
    if (member && group == nil) {
        if ([member.UserID isEqualToString:curUser.UserID]) {
            dict[@"fromName"] = @"我的手机";
            dict[@"toName"] = @"我的电脑";
        }
        
    }
    NSDictionary *dict1 = [NSDictionary dictionaryWithObject:dict forKey:@"messageCommon"];
    NSString *body = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict1 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    [aMessage addChild:[DDXMLNode elementWithName:@"body" stringValue:body]];
    
    
    
    NSInteger i;
    if (type == PERSON) {
        i = 0;
    } else if (type == PINSHOUQI)
    {
        i = 1;
    } else if (type == NORMAL){
        i = 2;
    }
    
     NSString *strUrl = [NSString stringWithFormat:@"%@sendRedPacket.action?id=%@&userId=%@&userName=%@&num=%ld&cash=%.2f&pin=%ld",REDPACKETNET,relMessageId,curUser.UserID,curUser.UserName,(long)number,money,(long)i];
    NSString *requestUrl = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    operation.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        if ([responseObject[@"result"] isEqualToString:@"success"]) {
             successHandle(operation,responseObject);
            [self handleMessage:aMessage curUser:curUser member:member group:group];
            [[CXmppMgr shareInstance] sendElement:aMessage];
            dispatch_async(dispatch_get_main_queue(), ^{
               [[NSNotificationCenter defaultCenter] postNotificationName:@"MineDIdSendMessage" object:nil];
            });
        }
       else
       {
           successHandle(operation,responseObject);
       }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureHandle(operation,error);
    }];
    [_queen addOperation:operation];
}
-(void)sendMapMessage:(UIImage *)mapImage messageID:(NSString *)messageId curUser:(CContactModel *)curUser member:(CContactModel *)member group:(CGroupModel *)group latitude:(double)latitude longitude:(double)longitude
{
    if (mapImage == nil) {
        return;
    }
    NSString *timeStamp = [UIUtil getCurrentTimeStamp];
    NSData *bigImageData = UIImageJPEGRepresentation(mapImage, 1.0);
    
    
    UIImage *aImg = [UIImage scaleFromImage:mapImage scaledToWidth:170];
    NSData *imgData = UIImageJPEGRepresentation(aImg, 10 / (float)bigImageData.length);
    NSInteger filelenth = [bigImageData length];
    
    NSString *fileName;
    XMPPMessage *aMessage;
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    if(member && group == nil)
    {
        aMessage=[XMPPMessage messageWithType:@"chat" to:[XMPPJID jidWithString:[NSString stringWithFormat:@"%@@pcapp.%@",member.UserCode,[[CXmppMgr shareInstance] xmppStream].hostName]]];
        
        if ([member.UserID isEqualToString:curUser.UserID]) {
            [aMessage addAttributeWithName:@"commonality" stringValue:@"messagePcapp"];
            
        }
        
        dict[@"toId"] = member.UserID;
        dict[@"toName"] = member.UserName;
        
        fileName = [NSString stringWithFormat:@"location,%f,%f,%@___%@_s.jpg", latitude,longitude,timeStamp,curUser.UserID];
        [[ChildHoodService defaultService] savePersonalUpLoadImageWithFileName:fileName content:bigImageData userId:curUser.UserID];
    } else if (group && member == nil) {
        if (group.groupType == 1) {
            if (!group.isShow) {
                group.isShow = YES;
                [[CXmppRequestMgr shareInstance] updateDiscussInfoWithGroup:group];
            }
        }
        
        
        NSString* roomJid = [NSString stringWithFormat:@"%@@broadcast.%@",group.GroupId,[[CXmppMgr shareInstance] xmppStream].hostName];
        aMessage=[XMPPMessage messageWithType:@"groupchat" to:[XMPPJID jidWithString:roomJid]];
        dict[@"toId"] = group.GroupId;
        dict[@"groupId"] = group.GroupId;
        dict[@"toName"] = group.GroupName;
        
         fileName = [NSString stringWithFormat:@"location,%f,%f,%@___%@_s.jpg", latitude,longitude,timeStamp,curUser.UserID];
        [[ChildHoodService defaultService] saveGroupUpLoadImageWithFileName:fileName content:bigImageData groupId:group.GroupId];
        
    }
    [aMessage addAttributeWithName:@"from" stringValue:[NSString stringWithFormat:@"%@@%@",curUser.UserCode,[[CXmppMgr shareInstance] xmppStream].hostName]];
    
    CServerSettingModel *settingModel = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    
    dict[@"length"] = @(filelenth);
    dict[@"fromId"] = curUser.UserID;
    dict[@"body"] = [NSString stringWithFormat:@"かΨimageΨか%@￠",fileName];
    dict[@"fileName"] = fileName;
    dict[@"nodeId"] = @"";
    dict[@"fromName"] = curUser.UserName;
    dict[@"status"] = @"";
    dict[@"type"] = @"image";
    dict[@"stream"] = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:@{fileName:[imgData base64Encoding]} options:0 error:nil] encoding:NSUTF8StringEncoding];
    dict[@"sendTime"] = timeStamp;
    dict[@"companyId"] = M_STOREVALUE(settingModel.companyId);
    
    NSString *idkey = settingModel.yuLiuZiduan1;
    if (M_ISSTRNULL(idkey)) {
        idkey = [self randomChar];
    }
    
    NSString *relMessageId = nil;
    if (M_ISSTRNULL(messageId)) {
        relMessageId = [NSString stringWithFormat:@"%@%@",timeStamp,idkey];
    } else {
        relMessageId = messageId;
    }
    
    dict[@"messageId"] = relMessageId;
    [aMessage addAttributeWithName:@"id" stringValue:relMessageId];
    
    if (member && group == nil) {
        if ([member.UserID isEqualToString:curUser.UserID]) {
            dict[@"fromName"] = @"我的手机";
            dict[@"toName"] = @"我的电脑";
        }
        
    }
    
    NSDictionary *dict1 = [NSDictionary dictionaryWithObject:dict forKey:@"messageCommon"];
    NSString *body = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict1 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    [aMessage addChild:[DDXMLNode elementWithName:@"body" stringValue:body]];
    
    [self handleMessage:aMessage curUser:curUser member:member group:group];
    if (group) {
        
        [self uploadGroupWithContentData:bigImageData fileNmae:fileName groupId:group.GroupId dataType:@"image" fileType:@"jpg" successHandel:^(NSURLSessionDataTask *task, id responseObject) {
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
            if ([dic[@"result"] isEqualToString:@"success"]) {
                [[CXmppMgr shareInstance] sendElement:aMessage];
            }
            else
            {
                [self updateMessageSendStatusWithMessageId:relMessageId];
            }
            
        } filarueHandle:^(NSURLSessionDataTask *task, NSError *error) {
            [self updateMessageSendStatusWithMessageId:relMessageId];
            
        } progressHandle:^(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
        }];
        
    } else {
        [self uploadWithContentData:bigImageData fileNmae:fileName userId:curUser.UserID dataType:@"image" fileType:@"jpg" successHandel:^(NSURLSessionDataTask *task, id responseObject) {
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
            if ([dic[@"result"] isEqualToString:@"success"]) {
                [[CXmppMgr shareInstance] sendElement:aMessage];
            }
            else
            {
                [self updateMessageSendStatusWithMessageId:relMessageId];
            }
            
        } filarueHandle:^(NSURLSessionDataTask *task, NSError *error) {
            [self updateMessageSendStatusWithMessageId:relMessageId];
            
        } progressHandle:^(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
            
        }];
    }
    [[NSNotificationCenter defaultCenter] postNotificationName:@"MineDIdSendMessage" object:nil];

}

- (void)sendVideoMessage:(NSData *)videoData videoImage:(UIImage *)videoImage messageId:(NSString *)messageId curUser:(CContactModel *)curUser member:(CContactModel *)member group:(CGroupModel *)group fileName:(NSString *)fileName
{
    if (videoImage == nil || videoData == nil) {
        return;
    }
    NSString *timeStamp = [UIUtil getCurrentTimeStamp];
    NSData *bigImageData = UIImageJPEGRepresentation(videoImage,1);
    UIImage *aImg = [UIImage scaleFromImage:videoImage scaledToWidth:170];
    NSData *imgData = UIImageJPEGRepresentation(aImg, 10 / (float)bigImageData.length);
    NSInteger filelenth = [videoData length];
    
    XMPPMessage *aMessage;
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    if(member && group == nil)
    {
        aMessage=[XMPPMessage messageWithType:@"chat" to:[XMPPJID jidWithString:[NSString stringWithFormat:@"%@@pcapp.%@",member.UserCode,[[CXmppMgr shareInstance] xmppStream].hostName]]];
        
        if ([member.UserID isEqualToString:curUser.UserID]) {
            [aMessage addAttributeWithName:@"commonality" stringValue:@"messagePcapp"];
        }
        
        dict[@"toId"] = member.UserID;
        dict[@"toName"] = member.UserName;
        if (fileName == nil) {
            fileName = [NSString stringWithFormat:@"%@___%@___%@.mp4", curUser.UserID,timeStamp,timeStamp];
        }
        [[ChildHoodService defaultService] savePersonalUpLoadVideoWithFileName:fileName content:videoData userId:curUser.UserID];
    } else if (group && member == nil) {
        if (group.groupType == 1) {
            if (!group.isShow) {
                group.isShow = YES;
                [[CXmppRequestMgr shareInstance] updateDiscussInfoWithGroup:group];
            }
        }
        
        
        NSString* roomJid = [NSString stringWithFormat:@"%@@broadcast.%@",group.GroupId,[[CXmppMgr shareInstance] xmppStream].hostName];
        aMessage=[XMPPMessage messageWithType:@"groupchat" to:[XMPPJID jidWithString:roomJid]];
        dict[@"toId"] = group.GroupId;
        dict[@"groupId"] = group.GroupId;
        dict[@"toName"] = group.GroupName;
        if (fileName == nil) {
            fileName = [NSString stringWithFormat:@"%@___%@___%@.mp4", curUser.UserID,timeStamp,timeStamp];
        }
        [[ChildHoodService defaultService] saveGroupUpLoadVideoWithFileName:fileName content:videoData groupId:group.GroupId];
        
    }
    [aMessage addAttributeWithName:@"from" stringValue:[NSString stringWithFormat:@"%@@%@",curUser.UserCode,[[CXmppMgr shareInstance] xmppStream].hostName]];
    
    CServerSettingModel *settingModel = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    
    dict[@"length"] = @(filelenth);
    dict[@"fromId"] = curUser.UserID;
    dict[@"body"] = [NSString stringWithFormat:@"かΨvideoΨか%@￠",fileName];
    dict[@"fileName"] = fileName;
    dict[@"nodeId"] = @"";
    dict[@"fromName"] = curUser.UserName;
    dict[@"status"] = @"";
    dict[@"type"] = @"video";
    dict[@"stream"] = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:@{fileName:[imgData base64Encoding]} options:0 error:nil] encoding:NSUTF8StringEncoding];
    dict[@"sendTime"] = timeStamp;
    dict[@"companyId"] = M_STOREVALUE(settingModel.companyId);
    
    NSString *idkey = settingModel.yuLiuZiduan1;
    if (M_ISSTRNULL(idkey)) {
        idkey = [self randomChar];
    }
    
    NSString *relMessageId = nil;
    if (M_ISSTRNULL(messageId)) {
        relMessageId = [NSString stringWithFormat:@"%@%@",timeStamp,idkey];
    } else {
        relMessageId = messageId;
    }
    
    dict[@"messageId"] = relMessageId;
    [aMessage addAttributeWithName:@"id" stringValue:relMessageId];
    
    if (member && group == nil) {
        if ([member.UserID isEqualToString:curUser.UserID]) {
            dict[@"fromName"] = @"我的手机";
            dict[@"toName"] = @"我的电脑";
        }
        
    }
    
    
    NSDictionary *dict1 = [NSDictionary dictionaryWithObject:dict forKey:@"messageCommon"];
    NSString *body = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict1 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    [aMessage addChild:[DDXMLNode elementWithName:@"body" stringValue:body]];
    
    [self handleMessage:aMessage curUser:curUser member:member group:group];
    if (group) {
        
        [self uploadGroupWithContentData:videoData fileNmae:fileName groupId:group.GroupId dataType:@"video" fileType:@"mp4" successHandel:^(NSURLSessionDataTask *task, id responseObject) {
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
            if ([dic[@"result"] isEqualToString:@"success"]) {
                [[CXmppMgr shareInstance] sendElement:aMessage];
            }
            else
            {
                [self updateMessageSendStatusWithMessageId:relMessageId];
            }
            
        } filarueHandle:^(NSURLSessionDataTask *task, NSError *error) {
            [self updateMessageSendStatusWithMessageId:relMessageId];
            
        } progressHandle:^(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
        }];
        
    } else {
        [self uploadWithContentData:videoData fileNmae:fileName userId:curUser.UserID dataType:@"video" fileType:@"mp4" successHandel:^(NSURLSessionDataTask *task, id responseObject) {
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
            if ([dic[@"result"] isEqualToString:@"success"]) {
                [[CXmppMgr shareInstance] sendElement:aMessage];
            }
            else
            {
                [self updateMessageSendStatusWithMessageId:relMessageId];
            }
            
        } filarueHandle:^(NSURLSessionDataTask *task, NSError *error) {
            [self updateMessageSendStatusWithMessageId:relMessageId];
            
        } progressHandle:^(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
            
        }];
    }
    [[NSNotificationCenter defaultCenter] postNotificationName:@"MineDIdSendMessage" object:nil];

}
- (void)sendImageMessage:(UIImage *)image messageId:(NSString *)messageId index:(NSInteger)index  curUser:(CContactModel *)curUser member:(CContactModel *)member group:(CGroupModel *)group fileName:(NSString *)fileName
{
    
    if (image == nil) {
        return;
    }
    NSString *timeStamp = [UIUtil getCurrentTimeStamp];
    NSData *bigImageData = UIImageJPEGRepresentation(image,1);
    if (bigImageData.length/1000 > 1000) {
        bigImageData = UIImageJPEGRepresentation(image,0.5);
    }
    UIImage *aImg = [UIImage scaleFromImage:image scaledToWidth:170];
    NSData *imgData = UIImageJPEGRepresentation(aImg, 10 / (float)bigImageData.length);
    NSInteger filelenth = [bigImageData length];
    
    XMPPMessage *aMessage;
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    if(member && group == nil)
    {
        aMessage=[XMPPMessage messageWithType:@"chat" to:[XMPPJID jidWithString:[NSString stringWithFormat:@"%@@pcapp.%@",member.UserCode,[[CXmppMgr shareInstance] xmppStream].hostName]]];
        
        if ([member.UserID isEqualToString:curUser.UserID]) {
            [aMessage addAttributeWithName:@"commonality" stringValue:@"messagePcapp"];
        }

        dict[@"toId"] = member.UserID;
        dict[@"toName"] = member.UserName;
        if (fileName == nil) {
            fileName = [NSString stringWithFormat:@"%zd___%@___%@_s.jpg", index,timeStamp,timeStamp];
        }
        [[ChildHoodService defaultService] savePersonalUpLoadImageWithFileName:fileName content:bigImageData userId:curUser.UserID];
    } else if (group && member == nil) {
        if (group.groupType == 1) {
            if (!group.isShow) {
                group.isShow = YES;
                [[CXmppRequestMgr shareInstance] updateDiscussInfoWithGroup:group];
            }
        }

        
        NSString* roomJid = [NSString stringWithFormat:@"%@@broadcast.%@",group.GroupId,[[CXmppMgr shareInstance] xmppStream].hostName];
        aMessage=[XMPPMessage messageWithType:@"groupchat" to:[XMPPJID jidWithString:roomJid]];
        dict[@"toId"] = group.GroupId;
        dict[@"groupId"] = group.GroupId;
        dict[@"toName"] = group.GroupName;
        if (fileName == nil) {
            fileName = [NSString stringWithFormat:@"%zd___%@___%@___%@_s.jpg",index,timeStamp,curUser.UserID,timeStamp];
        }
        
        [[ChildHoodService defaultService] saveGroupUpLoadImageWithFileName:fileName content:bigImageData groupId:group.GroupId];

    }
    [aMessage addAttributeWithName:@"from" stringValue:[NSString stringWithFormat:@"%@@%@",curUser.UserCode,[[CXmppMgr shareInstance] xmppStream].hostName]];
    
    CServerSettingModel *settingModel = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    
    dict[@"length"] = @(filelenth);
    dict[@"fromId"] = curUser.UserID;
    dict[@"body"] = [NSString stringWithFormat:@"かΨimageΨか%@￠",fileName];
    dict[@"fileName"] = fileName;
    dict[@"nodeId"] = @"";
    dict[@"fromName"] = curUser.UserName;
    dict[@"status"] = @"";
    dict[@"type"] = @"image";
    dict[@"stream"] = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:@{fileName:[imgData base64Encoding]} options:0 error:nil] encoding:NSUTF8StringEncoding];
    dict[@"sendTime"] = timeStamp;
    dict[@"companyId"] = M_STOREVALUE(settingModel.companyId);
    
    NSString *idkey = settingModel.yuLiuZiduan1;
    if (M_ISSTRNULL(idkey)) {
        idkey = [self randomChar];
    }
    
    NSString *relMessageId = nil;
    if (M_ISSTRNULL(messageId)) {
        relMessageId = [NSString stringWithFormat:@"%@%@",timeStamp,idkey];
    } else {
        relMessageId = messageId;
    }
    
    dict[@"messageId"] = relMessageId;
    [aMessage addAttributeWithName:@"id" stringValue:relMessageId];
    
    if (member && group == nil) {
        if ([member.UserID isEqualToString:curUser.UserID]) {
            dict[@"fromName"] = @"我的手机";
            dict[@"toName"] = @"我的电脑";
        }
        
    }

    
    NSDictionary *dict1 = [NSDictionary dictionaryWithObject:dict forKey:@"messageCommon"];
    NSString *body = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict1 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    [aMessage addChild:[DDXMLNode elementWithName:@"body" stringValue:body]];
    
    [self handleMessage:aMessage curUser:curUser member:member group:group];
    if (group) {
        
        [self uploadGroupWithContentData:bigImageData fileNmae:fileName groupId:group.GroupId dataType:@"image" fileType:@"jpg" successHandel:^(NSURLSessionDataTask *task, id responseObject) {
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
            if ([dic[@"result"] isEqualToString:@"success"]) {
                [[CXmppMgr shareInstance] sendElement:aMessage];
            }
            else
            {
                [self updateMessageSendStatusWithMessageId:relMessageId];
            }

        } filarueHandle:^(NSURLSessionDataTask *task, NSError *error) {
            [self updateMessageSendStatusWithMessageId:relMessageId];

        } progressHandle:^(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
        }];
        
    } else {
        [self uploadWithContentData:bigImageData fileNmae:fileName userId:curUser.UserID dataType:@"image" fileType:@"jpg" successHandel:^(NSURLSessionDataTask *task, id responseObject) {
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
            if ([dic[@"result"] isEqualToString:@"success"]) {
                [[CXmppMgr shareInstance] sendElement:aMessage];
            }
            else
            {
                [self updateMessageSendStatusWithMessageId:relMessageId];
            }
            
        } filarueHandle:^(NSURLSessionDataTask *task, NSError *error) {
            [self updateMessageSendStatusWithMessageId:relMessageId];
            
        } progressHandle:^(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {

        }];
    }
   [[NSNotificationCenter defaultCenter] postNotificationName:@"MineDIdSendMessage" object:nil];
}


- (void)sendFile:(CFileModel *)fileModel messageId:(NSString *)messageId curUser:(CContactModel *)curUser member:(CContactModel *)member group:(CGroupModel *)group
{
    NSString *timeStamp = [UIUtil getCurrentTimeStamp];
    __block XMPPMessage *aMessage;
    NSData *contentData = [[NSFileManager defaultManager] contentsAtPath:fileModel.LocalFilePath];
    if (!contentData) {
        return;
    }
    
    NSInteger  filelenth = [contentData length];
    
    NSString *maxSize = [USER_DEFAULT stringForKey:FILEMAXSIZE];
    if (maxSize.length > 0) {
         NSInteger maxSizeLenth = [[USER_DEFAULT stringForKey:FILEMAXSIZE] integerValue];
        if (filelenth > maxSizeLenth * 1024 * 1024) {
            [MBProgressHUD showError:[NSString stringWithFormat:@"上传的文件不能超过%zdM",maxSizeLenth]];
            return;
        }

    }
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    NSString *fileName;
    if(member && group == nil)
    {
        aMessage=[XMPPMessage messageWithType:@"chat" to:[XMPPJID jidWithString:[NSString stringWithFormat:@"%@@pcapp.%@",member.UserCode,[[CXmppMgr shareInstance] xmppStream].hostName]]];
        
        if ([member.UserID isEqualToString:curUser.UserID]) {
            [aMessage addAttributeWithName:@"commonality" stringValue:@"messagePcapp"];
            
        }

        
        dict[@"toId"] = member.UserID;
        dict[@"toName"] = member.UserName;
        fileName = [NSString stringWithFormat:@"%@___%@",timeStamp, fileModel.FileName];
        
        [[ChildHoodService defaultService] savePersonalUpLoadFileWithFileName:fileName content:contentData userId:curUser.UserID];
    } else if (group && member == nil) {
        
        if (group.groupType == 1) {
            if (!group.isShow) {
                group.isShow = YES;
                [[CXmppRequestMgr shareInstance] updateDiscussInfoWithGroup:group];
            }
        }

        
        NSString* roomJid = [NSString stringWithFormat:@"%@@broadcast.%@",group.GroupId,[[CXmppMgr shareInstance] xmppStream].hostName];
        aMessage=[XMPPMessage messageWithType:@"groupchat" to:[XMPPJID jidWithString:roomJid]];
        dict[@"toId"] = group.GroupId;
        dict[@"groupId"] = group.GroupId;
        dict[@"toName"] = group.GroupName;
        fileName = [NSString stringWithFormat:@"%@___%@___%@",timeStamp,curUser.UserID, fileModel.FileName];
        [[ChildHoodService defaultService] saveGroupUpLoadFileWithFileName:fileName content:contentData groupId:group.GroupId];
    }
    [aMessage addAttributeWithName:@"from" stringValue:[NSString stringWithFormat:@"%@@%@",curUser.UserCode,[[CXmppMgr shareInstance] xmppStream].hostName]];
    
    CServerSettingModel *settingModel = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    dict[@"length"] = @(filelenth);
    dict[@"fromId"] = curUser.UserID;
    dict[@"body"] = fileModel.FileName;
    dict[@"fileName"] = fileName;
    dict[@"nodeId"] = @"";
    dict[@"fromName"] = curUser.UserName;
    dict[@"status"] = @"yes/no";
    dict[@"type"] = @"file";
    dict[@"stream"] = @"";
    dict[@"companyId"] = M_STOREVALUE(settingModel.companyId);
    dict[@"sendTime"] = timeStamp;
    
    NSString *idkey = settingModel.yuLiuZiduan1;
    if (M_ISSTRNULL(idkey)) {
        idkey = [self randomChar];
    }
    
    NSString *relMessageId = nil;
    if (M_ISSTRNULL(messageId)) {
        relMessageId = [NSString stringWithFormat:@"%@%@",timeStamp,idkey];
    } else {
        relMessageId = messageId;
    }
    
    dict[@"messageId"] = relMessageId;
    [aMessage addAttributeWithName:@"id" stringValue:relMessageId];
    
    if (member && group == nil) {
        if ([member.UserID isEqualToString:curUser.UserID]) {
            dict[@"fromName"] = @"我的手机";
            dict[@"toName"] = @"我的电脑";
        }
 
    }
    

    NSDictionary *dict1 = [NSDictionary dictionaryWithObject:dict forKey:@"messageCommon"];
    NSString *body = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict1 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    [aMessage addChild:[DDXMLNode elementWithName:@"body" stringValue:body]];
    
    [self handleMessage:aMessage curUser:curUser member:member group:group];
    
    
    
    if (group) {

        [self uploadGroupWithContentData:contentData fileNmae:fileName groupId:group.GroupId dataType:@"file" fileType:@"file" successHandel:^(NSURLSessionDataTask *task, id responseObject) {
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
            if ([dic[@"result"] isEqualToString:@"success"]) {
                [[CXmppMgr shareInstance] sendElement:aMessage];
                [ChildHoodService defaultService].fileModel = nil;
            }
            else
            {
                [self updateMessageSendStatusWithMessageId:relMessageId];
                [ChildHoodService defaultService].fileModel = nil;
            }
            
        } filarueHandle:^(NSURLSessionDataTask *task, NSError *error) {
            [self updateMessageSendStatusWithMessageId:relMessageId];
            [ChildHoodService defaultService].fileModel = nil;
            

        } progressHandle:^(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
        }];
    } else {
        [self uploadWithContentData:contentData fileNmae:fileName userId:curUser.UserID dataType:@"file" fileType:@"file" successHandel:^(NSURLSessionDataTask *task, id responseObject) {
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
            if ([dic[@"result"] isEqualToString:@"success"]) {
                [[CXmppMgr shareInstance] sendElement:aMessage];
            }
            else
            {
                [self updateMessageSendStatusWithMessageId:relMessageId];
            }
            
        } filarueHandle:^(NSURLSessionDataTask *task, NSError *error) {
            [self updateMessageSendStatusWithMessageId:relMessageId];
            

        } progressHandle:^(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
        }];
    }
   [[NSNotificationCenter defaultCenter] postNotificationName:@"MineDIdSendMessage" object:nil];
}

- (void)sendVoiceMessageWihtCurUser:(CContactModel *)curUser messageId:(NSString *)messageId member:(CContactModel *)member group:(CGroupModel *)group fileName:(NSString *)fileName timeLenth:(NSInteger)timeLenth
{
    NSString *timeStamp = [UIUtil getCurrentTimeStamp];
    __block XMPPMessage *aMessage;
    
    NSData *voiceData;
     NSString *amrFileName = [fileName stringByReplacingOccurrencesOfString:@".wav" withString:@".amr"];
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    if(member && group == nil)
    {
        voiceData = [[NSData alloc] initWithContentsOfFile:[[[ChildHoodService defaultService] personalUploadSoundPathWithUserId:curUser.UserID] stringByAppendingPathComponent:fileName]];
        if (voiceData == nil) {
            return ;
        }
        if (![fileName isEqualToString:amrFileName]) {
            
            voiceData = [VoiceConverter wavToAmr:voiceData];
            [[ChildHoodService defaultService] savePersonalUpLoadSoundWithFileName:amrFileName content:voiceData userId:curUser.UserID];
        }
        aMessage=[XMPPMessage messageWithType:@"chat" to:[XMPPJID jidWithString:[NSString stringWithFormat:@"%@@pcapp.%@",member.UserCode,[[CXmppMgr shareInstance] xmppStream].hostName]]];
        
        dict[@"toId"] = member.UserID;
        dict[@"toName"] = member.UserName;
    } else if (group && member == nil) {
        
        if (group.groupType == 1) {
            if (!group.isShow) {
                group.isShow = YES;
                [[CXmppRequestMgr shareInstance] updateDiscussInfoWithGroup:group];
            }
        }

        
        voiceData = [[NSData alloc] initWithContentsOfFile:[[[ChildHoodService defaultService] groupUploadSoundPathWithGroupId:group.GroupId] stringByAppendingPathComponent:fileName]];
        if (voiceData == nil) {
            return ;
        }
        if (![fileName isEqualToString:amrFileName]) {
            
            voiceData = [VoiceConverter wavToAmr:voiceData];
            [[ChildHoodService defaultService] saveGroupUpLoadSoundWithFileName:amrFileName content:voiceData groupId:group.GroupId];

        }

        NSString* roomJid = [NSString stringWithFormat:@"%@@broadcast.%@",group.GroupId,[[CXmppMgr shareInstance] xmppStream].hostName];
        aMessage=[XMPPMessage messageWithType:@"groupchat" to:[XMPPJID jidWithString:roomJid]];
        dict[@"toId"] = group.GroupId;
        dict[@"groupId"] = group.GroupId;
        dict[@"toName"] = group.GroupName;
    }
    
    [aMessage addAttributeWithName:@"from" stringValue:[NSString stringWithFormat:@"%@@%@",curUser.UserCode,[[CXmppMgr shareInstance] xmppStream].hostName]];
    
    
   
    CServerSettingModel *settingModel = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    dict[@"length"] = @(voiceData.length);
    dict[@"fromId"] = curUser.UserID;
    dict[@"body"] = [NSString stringWithFormat:@"%zd",timeLenth];
    dict[@"fileName"] = amrFileName;
    dict[@"nodeId"] = @"";
    dict[@"fromName"] = curUser.UserName;
    dict[@"status"] = @"";
    dict[@"type"] = @"voice";
    dict[@"stream"] = @"";
    dict[@"companyId"] = M_STOREVALUE(settingModel.companyId);
    dict[@"sendTime"] = timeStamp;
   
    NSString *idkey = settingModel.yuLiuZiduan1;
    if (M_ISSTRNULL(idkey)) {
        idkey = [self randomChar];
    }
    
    NSString *relMessageId = nil;
    if (M_ISSTRNULL(messageId)) {
        relMessageId = [NSString stringWithFormat:@"%@%@",timeStamp,idkey];
    } else {
        relMessageId = messageId;
    }
    
    dict[@"messageId"] = relMessageId;
    [aMessage addAttributeWithName:@"id" stringValue:relMessageId];
    NSDictionary *dict1 = [NSDictionary dictionaryWithObject:dict forKey:@"messageCommon"];
    NSString *body = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict1 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    [aMessage addChild:[DDXMLNode elementWithName:@"body" stringValue:body]];
    
    [self handleMessage:aMessage curUser:curUser member:member group:group];
    
    
    
    if (group) {
        [self uploadGroupWithContentData:voiceData fileNmae:amrFileName groupId:group.GroupId dataType:@"voice" fileType:@"amr" successHandel:^(NSURLSessionDataTask *task, id responseObject) {
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
            if ([dic[@"result"] isEqualToString:@"success"]) {
                [[CXmppMgr shareInstance] sendElement:aMessage];
            }
            else
            {
                [self updateMessageSendStatusWithMessageId:relMessageId];
            }
            
        } filarueHandle:^(NSURLSessionDataTask *task, NSError *error) {
            [self updateMessageSendStatusWithMessageId:relMessageId];
            

        } progressHandle:^(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
            
        }];
        
    } else {
        [self uploadWithContentData:voiceData fileNmae:amrFileName userId:curUser.UserID dataType:@"voice" fileType:@"amr" successHandel:^(NSURLSessionDataTask *task, id responseObject) {
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
            if ([dic[@"result"] isEqualToString:@"success"]) {
                [[CXmppMgr shareInstance] sendElement:aMessage];
            }
            else
            {
                [self updateMessageSendStatusWithMessageId:relMessageId];
            }
            
        } filarueHandle:^(NSURLSessionDataTask *task, NSError *error) {
            [self updateMessageSendStatusWithMessageId:relMessageId];
            

        } progressHandle:^(NSURLSession *session, NSURLSessionTask *task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
            
        }];
    }
    [[NSNotificationCenter defaultCenter] postNotificationName:@"MineDIdSendMessage" object:nil];
}

- (NSString *)randomChar
{
    NSInteger random = arc4random_uniform(999999);
    return [NSString stringWithFormat:@"%zd",random];
}
- (void)handleMessage:(XMPPMessage *)aMessage curUser:(CContactModel *)curUser member:(CContactModel *)member group:(CGroupModel *)group
{
    
    CMessageModel *model = nil;
    if ([aMessage isChatMessageWithBody]) {
        
        NSString *body = [[aMessage elementForName:@"body"] stringValue];
        
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[body dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
        NSDictionary *subDic = dict[@"messageCommon"];
        
        model = [[CMessageModel alloc] init];
        
        model.MessageContent = [subDic stringForKey:@"body"];
        model.FileSize = [NSString stringWithFormat:@"%@",[subDic objectForKey:@"length"]];
        model.MineJid = [aMessage.from.bare stringByReplacingOccurrencesOfString:@"pcapp." withString:@""];
        model.FriendJid = [aMessage.to.bare stringByReplacingOccurrencesOfString:@"pcapp." withString:@""];
        model.FileName = [subDic stringForKey:@"fileName"];
        model.Stream = [subDic stringForKey:@"stream"];
        model.MessageId = [NSString stringWithFormat:@"%@",[subDic objectForKey:@"messageId"]];
        model.TimeStamp = [NSString stringWithFormat:@"%@",[subDic objectForKey:@"sendTime"]];
        //        model.GroupId = [subDic stringForKey:@"toId"];
        model.MineUserId = [subDic stringForKey:@"fromId"];
        model.FriendUserId = [subDic stringForKey:@"toId"];
        model.FriendUserName = member.UserName;
        model.MineUserName = curUser.UserName;
        model.MessageSendedStatus = kMessageSending;
        model.SoundPlayStatus = MessageSoundPlayed;
        model.isMineSend = YES;
        model.ReadStatus = YES;
        model.IsShowInmessageList = YES;
        if (model.TimeStamp.length <= 0) {
            model.TimeStamp = [UIUtil getCurrentTimeStamp];
        }
        
        model.MessageType = [subDic stringForKey:@"type"];
        if ([model.MessageType isEqualToString:@"image"]||[model.MessageType isEqualToString:@"map"]||[model.MessageType isEqualToString:@"video"]) {
            
            model.Stream = [[NSJSONSerialization JSONObjectWithData:[subDic[@"stream"] dataUsingEncoding:NSUTF8StringEncoding]  options:0 error:nil] objectForKey:model.FileName];
            
        }
        BOOL isAuthenticated = [[CXmppMgr shareInstance].xmppStream isAuthenticated];
        if (!isAuthenticated) {
            model.MessageSendedStatus = kMessageSendFailed;
        }
        [self.messageMgr insertMessage:model];
        
    } else if ([aMessage isGroupMessageWithBody]) {
        
        NSString *body = [[aMessage elementForName:@"body"] stringValue];
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[body dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
        NSDictionary *subDic = dict[@"messageCommon"];
        
        model = [[CMessageModel alloc] init];
        
        model.MessageContent = [subDic stringForKey:@"body"];
        model.MineJid = [aMessage.from.bare stringByReplacingOccurrencesOfString:@"pcapp." withString:@""];
        model.FriendJid = [aMessage.to.bare stringByReplacingOccurrencesOfString:@"broadcast." withString:@""];
        model.FileName = [subDic stringForKey:@"fileName"];
        model.Stream = [subDic stringForKey:@"stream"];
        model.FileSize = [NSString stringWithFormat:@"%@",[subDic objectForKey:@"length"]];
        model.MessageId = [NSString stringWithFormat:@"%@",[subDic objectForKey:@"messageId"]];
        model.TimeStamp = [NSString stringWithFormat:@"%@",[subDic objectForKey:@"sendTime"]];
        if (model.TimeStamp.length <= 0) {
            model.TimeStamp = [UIUtil getCurrentTimeStamp];
        }
        model.GroupId = [subDic stringForKey:@"groupId"];
        model.MineUserId = [subDic stringForKey:@"fromId"];
        model.FriendUserId = [subDic stringForKey:@"toId"];
        model.FriendUserName = group.GroupName;
        model.MineUserName = curUser.UserName;
        model.MessageSendedStatus = kMessageSending;
        model.SoundPlayStatus = MessageSoundPlayed;
        model.isMineSend = YES;
        model.ReadStatus = YES;
        model.IsShowInmessageList = YES;
        model.MessageType = [subDic stringForKey:@"type"];
        if ([model.MessageType isEqualToString:@"image"]||[model.MessageType isEqualToString:@"map"]||[model.MessageType isEqualToString:@"video"]) {
            model.Stream = [[NSJSONSerialization JSONObjectWithData:[subDic[@"stream"] dataUsingEncoding:NSUTF8StringEncoding]  options:0 error:nil] objectForKey:model.FileName];
        }
        model.yuLiuZiduan2 = group.groupType;
        if (![UIUtil isNetworkReachable]) {
            model.MessageSendedStatus = kMessageSendFailed;

        }
        [self.messageMgr insertMessage:model];
        
    }
    
    
    
}



- (void)getDelAndDisableUserWithSuccessHandel:(void (^)(AFHTTPRequestOperation *operation, id responseObject))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failureHandle
{
//    CServerSettingMgr *serverMgr = [[CServerSettingMgr alloc] init];
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSString *localServerAddr = serverSetting.IMIp;
    NSInteger openFirePort = serverSetting.IMPort;
    NSString *userName = @"admin";
    
    
    NSRange range ;
    range.location = 8;
    range.length = 16;
    NSString *paddword = [[@"88888888" stringFromMD5] substringWithRange:range];
    
    
    NSString *urlStr =[NSString stringWithFormat:@"http://%@:%zd/imconsole/general_getDelAndDisableUser.action?userName=%@&password=%@&companyId=%@", localServerAddr, openFirePort, userName, paddword,serverSetting.companyId];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
//    operation.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/json"];
    
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successHandle(operation, responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureHandle(operation, error);
    }];
    [_queen addOperation:operation];

}

//讨论组相关
- (void)creatDiscussWithGroup:(CGroupModel *)group curUser:(CContactModel *)curUser
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"discussiongroupcreate"];
    //74e5c1f537d5e28e626b45e5bda31008
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:discussiongroupcreate"];
    //    [attrs setName:GroupId];
    DDXMLNode *attrs1 =[DDXMLNode attributeWithName:@"groupName" stringValue:group.GroupName];
    DDXMLNode *attrs2 = [DDXMLNode attributeWithName:@"type" stringValue:[NSString stringWithFormat:@"%zd",group.groupType]];
    DDXMLNode *attrs3 = [DDXMLNode attributeWithName:@"isHidden" stringValue:[NSString stringWithFormat:@"%zd",group.isShow?1:0]];
    
    NSString *companyId = M_STOREVALUE([[CFolderMgr shareInstance].serSettingMgr getSetting].companyId);
     DDXMLNode *attrs4 =[DDXMLNode attributeWithName:@"companyId" stringValue:companyId];
    
    DDXMLNode *attrs5 =[DDXMLNode attributeWithName:@"groupIntroduction" stringValue:group.GroupIntroduction];
    DDXMLNode *attrs6 =[DDXMLNode attributeWithName:@"groupNotice" stringValue:group.GroupNotice];
    
    DDXMLNode *attrs7 =[DDXMLNode attributeWithName:@"ownerName" stringValue:curUser.UserName];
    DDXMLNode *attrs8 =[DDXMLNode attributeWithName:@"ownerId" stringValue:curUser.UserID];
    
    DDXMLNode *groupEle = [DDXMLNode elementWithName:@"group" children:nil attributes:[NSArray arrayWithObjects:attrs1,attrs2,attrs3,attrs4,attrs5,attrs6,attrs7,attrs8, nil]];
    
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:groupEle, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    
    [[CXmppMgr shareInstance] sendElement:aIQ];

}
- (void)addDiscussMemberwithGroup:(CGroupModel *)group members:(NSArray *)members curUser:(CContactModel *)curUser
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"discussiongroupcremem"];
    //74e5c1f537d5e28e626b45e5bda31008
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:discussiongroupcremem"];
    //    [attrs setName:GroupId];
    DDXMLNode *attrs1 =[DDXMLNode elementWithName:@"groupName" stringValue:group.GroupName];
    DDXMLNode *attrs2 = [DDXMLNode elementWithName:@"type" stringValue:[NSString stringWithFormat:@"%zd",group.groupType]];
    DDXMLNode *attrs3 = [DDXMLNode elementWithName:@"groupId" stringValue:M_STOREVALUE(group.GroupId)];
    
    
    NSMutableString *memStr = [NSMutableString string];
    NSString *mem = nil;
    
    for (CContactModel *contact in members) {
        [memStr appendFormat:@"%@@%@;",contact.UserCode,contact.UserID];
    }
    if (curUser) {
        [memStr appendFormat:@"%@@%@",curUser.UserCode,curUser.UserID];
        mem = memStr;
    } else {
        mem = [memStr substringToIndex:memStr.length - 1];
    }
    
    
    DDXMLNode *attrs4 =[DDXMLNode elementWithName:@"members" stringValue:mem];
    
    
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:attrs1,attrs2,attrs3,attrs4, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    
    [[CXmppMgr shareInstance] sendElement:aIQ];

}
- (void)updateDiscussInfoWithGroup:(CGroupModel *)group
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"discussiongroupupdate"];
    //74e5c1f537d5e28e626b45e5bda31008
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:discussiongroupupdate"];
    //    [attrs setName:GroupId];
    DDXMLNode *attrs1 =[DDXMLNode attributeWithName:@"groupName" stringValue:group.GroupName];
    DDXMLNode *attrs2 = [DDXMLNode attributeWithName:@"type" stringValue:[NSString stringWithFormat:@"%zd",group.groupType]];
    DDXMLNode *attrs3 = [DDXMLNode attributeWithName:@"groupCode" stringValue:M_STOREVALUE(group.GroupId)];
    
    DDXMLNode *attrs4 =[DDXMLNode attributeWithName:@"groupNotice" stringValue:group.GroupName];
    DDXMLNode *attrs5 = [DDXMLNode attributeWithName:@"isHidden" stringValue:[NSString stringWithFormat:@"%zd",group.isShow?1:0]];
    DDXMLNode *attrs6 = [DDXMLNode attributeWithName:@"groupIntroduction" stringValue:@""];
    
    DDXMLNode *groupEle = [DDXMLNode elementWithName:@"group" children:nil attributes:[NSArray arrayWithObjects:attrs1,attrs2,attrs3,attrs4,attrs5,attrs6, nil]];

    
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:groupEle, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    
    
    [[CXmppMgr shareInstance] sendElement:aIQ];

}

//退出讨论组
- (void)signOutDiscussWithGroup:(CGroupModel *)group curUser:(CContactModel *)curUser
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"discussiongroupexitmem"];
    //74e5c1f537d5e28e626b45e5bda31008
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:discussiongroupexitmem"];
    //    [attrs setName:GroupId];
    DDXMLNode *attrs1 =[DDXMLNode elementWithName:@"groupName" stringValue:group.GroupName];
    DDXMLNode *attrs2 = [DDXMLNode elementWithName:@"type" stringValue:[NSString stringWithFormat:@"%zd",group.groupType]];
    DDXMLNode *attrs3 = [DDXMLNode elementWithName:@"groupId" stringValue:M_STOREVALUE(group.GroupId)];
    
    DDXMLNode *attrs4 =[DDXMLNode elementWithName:@"userId" stringValue:curUser.UserID];
    
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:attrs1,attrs2,attrs3,attrs4, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    

    [[CXmppMgr shareInstance] sendElement:aIQ];

}
//删除讨论组
- (void)delDiscussWithGroup:(CGroupModel *)group
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"discussiongroupdel"];
    //74e5c1f537d5e28e626b45e5bda31008
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:discussiongroupdel"];
    //    [attrs setName:GroupId];
    DDXMLNode *attrs1 =[DDXMLNode elementWithName:@"groupname" stringValue:group.GroupName];
    DDXMLNode *attrs2 = [DDXMLNode elementWithName:@"type" stringValue:[NSString stringWithFormat:@"%zd",group.groupType]];
    DDXMLNode *attrs3 = [DDXMLNode elementWithName:@"groupId" stringValue:M_STOREVALUE(group.GroupId)];
    
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:attrs1,attrs2,attrs3, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    
    
    [[CXmppMgr shareInstance] sendElement:aIQ];

}

//删除讨论组成员
- (void)delDiscussMembersWithGroup:(CGroupModel *)group contact:(CContactModel *)contact
{
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"discussiongroupdelmem"];
    //74e5c1f537d5e28e626b45e5bda31008
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:discussiongroupdelmem"];
    //    [attrs setName:GroupId];
    DDXMLNode *attrs1 =[DDXMLNode elementWithName:@"members" stringValue:[NSString stringWithFormat:@"%@@%@",contact.UserCode,contact.UserID]];
    DDXMLNode *attrs2 = [DDXMLNode elementWithName:@"type" stringValue:[NSString stringWithFormat:@"%zd",group.groupType]];
    DDXMLNode *attrs3 = [DDXMLNode elementWithName:@"groupId" stringValue:M_STOREVALUE(group.GroupId)];
    
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:attrs1,attrs2,attrs3, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    
    
    [[CXmppMgr shareInstance] sendElement:aIQ];

}

- (void)getKefuList
{
    
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    XMPPIQ *aIQ;
    aIQ = [XMPPIQ iqWithType:@"get" elementID:@"getcompanykf"];
    //74e5c1f537d5e28e626b45e5bda31008
    DDXMLNode *attrs =[DDXMLNode attributeWithName:@"xmlns" stringValue:@"com:im:wanzhao:getcompanykf"];
    //    [attrs setName:GroupId];
    DDXMLNode *attrs3 = [DDXMLNode elementWithName:@"companyId" stringValue:M_STOREVALUE(serverSetting.companyId)];
    DDXMLNode *query = [DDXMLNode elementWithName:@"query" children:[NSArray arrayWithObjects:attrs3, nil] attributes:[NSArray arrayWithObjects:attrs, nil]];
    [aIQ addChild:query];
    
    
    [[CXmppMgr shareInstance] sendElement:aIQ];

    
    [USER_DEFAULT setBool:NO forKey:isKeFuCompleted];
    [USER_DEFAULT synchronize];

}

// 发布分享
- (void)composeShareWithContact:(CContactModel *)contact shareId:(NSString *)shareId content:(NSString *)content type:(NSString *)type imageArray:(NSArray *)imageArray visibleUserId:(NSString *)visibleUserId successHandel:(void (^)(AFHTTPRequestOperation *, id))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *, NSError *))failureHandle
{
    __block AFHTTPRequestOperation *operation;
    [USER_DEFAULT setBool:NO forKey:@"sendOK"];
    [USER_DEFAULT synchronize];
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSRange range ;
    range.location = 8;
    range.length = 16;
    NSString *paddword = [[@"88888888" stringFromMD5] substringWithRange:range];

    NSString *timeStamp = [UIUtil getCurrentTimeStamp];
    NSString *fileName = nil;
    NSMutableArray *imageNameArray = [NSMutableArray array];
    NSMutableArray *operationArray = [NSMutableArray array];
    for (int i = 0; i < imageArray.count; i ++) {
        UIImage *image = imageArray[i];
        NSData *imgData = UIImageJPEGRepresentation(image, 0.5f);
        fileName = [NSString stringWithFormat:@"%@___%@___%zd.jpg",contact.UserID,timeStamp,i];
        NSDictionary *dict = @{@"url":fileName};
        [imageNameArray addObject:dict];
        
       NSString *urlStr =[NSString stringWithFormat:@"http://%@:%zd/imconsole/mobileFile_fileUpload.action?userName=%@&password=%@&companyId=%@&type=%@&filename=%@&userId=%@&from=ios&uploadType=circle", serverSetting.IMIp, serverSetting.IMPort, @"admin", paddword, M_STOREVALUE(serverSetting.companyId), @"image", fileName, contact.UserID];
        NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
        NSMutableURLRequest *request = [serializer multipartFormRequestWithMethod:@"POST" URLString:requestUrl parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
            [formData appendPartWithFileData:imgData name:fileName fileName:fileName mimeType:@"image"];
        } error:nil];
        
        AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
        operation.responseSerializer = [AFJSONResponseSerializer serializer];
        
        [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
            if (![responseObject[@"result"] isEqualToString:@"success"]) {
                [operation cancel];
                [USER_DEFAULT setBool:YES forKey:@"sendOK"];
                [USER_DEFAULT synchronize];
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        }];
        [operationArray addObject:operation];
    }

    
    
    
    
    NSDictionary *dict1 = @{@"companyId":M_STOREVALUE(serverSetting.companyId),@"userName":M_STOREVALUE(contact.UserName),@"userId":M_STOREVALUE(contact.UserID),@"type":type,@"content":M_STOREVALUE(content),@"imageName":imageNameArray,@"visibleUserId":M_STOREVALUE(visibleUserId),@"id":@(shareId.longLongValue)};
    NSString *str1 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict1 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    NSDictionary *dict2 = @{@"key":@"efeng",@"text":str1};
    NSString *str2 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict2 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    
    
    NSString *urlStr = [NSString stringWithFormat:@"http://%@:%zd/imconsole/circleContent_addReleaseContent.action?param=%@", M_STOREVALUE(serverSetting.IMIp),serverSetting.IMPort,[self getDesAndBase64WithString:str2]];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
   operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
//    operation.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/json"];
    
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
            successHandle(operation,responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [USER_DEFAULT setBool:YES forKey:@"sendOK"];
        [USER_DEFAULT synchronize];
        failureHandle(operation,error);
       
    }];
    
    for (int i = 0; i < operationArray.count; i ++) {
        AFHTTPRequestOperation *op = operationArray[i];
        [operation addDependency:op];
        [_queen addOperation:op];
    }
    [_queen addOperation:operation];

}
//获取分享内容列表
- (AFHTTPRequestOperation *)getShareListWithDate:(NSString *)date findType:(NSString *)findType userId:(NSString *)userId releaseUserId:(NSString *)releaseUserId successHandel:(void (^)(AFHTTPRequestOperation *, id))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *, NSError *))failureHandle
{
 
    long long temDate = [date longLongValue];
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSDictionary *dict1 = @{@"companyId":M_STOREVALUE(serverSetting.companyId),@"date":[NSNumber numberWithLongLong:temDate],@"userId":M_STOREVALUE(userId),@"releaseUserId":M_STOREVALUE(releaseUserId),@"findType":M_STOREVALUE(findType)};
    NSString *str1 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict1 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    NSDictionary *dict2 = @{@"key":@"efeng",@"text":str1};
    NSString *str2 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict2 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    
    
    NSString *urlStr = [NSString stringWithFormat:@"http://%@:%zd/imconsole/circleContent_list.action?param=%@", M_STOREVALUE(serverSetting.IMIp),serverSetting.IMPort,[self getDesAndBase64WithString:str2]];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    
    
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureHandle(operation,error);
        
       
    }];
    [_queen addOperation:operation];
    return operation;

}
//删除分享
- (void)delShareWithDate:(NSString *)date shareId:(NSString *)shareId successHandel:(void (^)(AFHTTPRequestOperation *, id))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *, NSError *))failureHandle
{
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSDictionary *dict1 = @{@"companyId":M_STOREVALUE(serverSetting.companyId),@"date":M_STOREVALUE(date),@"id":@(shareId.longLongValue)};
    NSString *str1 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict1 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    NSDictionary *dict2 = @{@"key":@"efeng",@"text":str1};
    NSString *str2 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict2 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    
    
    NSString *urlStr = [NSString stringWithFormat:@"http://%@:%zd/imconsole/circleContent_deleteContent.action?param=%@", M_STOREVALUE(serverSetting.IMIp),serverSetting.IMPort,[self getDesAndBase64WithString:str2]];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    
    
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureHandle(operation,error);
        
        
    }];
    [_queen addOperation:operation];

}

//获取已删除内容ID列表
- (AFHTTPRequestOperation *)getDelShareListWithDate:(NSString *)date userId:(NSString *)userId successHandel:(void (^)(AFHTTPRequestOperation *operation, id responseObject))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failureHandle
{
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSDictionary *dict1 = @{@"companyId":M_STOREVALUE(serverSetting.companyId),@"date":M_STOREVALUE(date),@"userId":M_STOREVALUE(userId)};
    NSString *str1 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict1 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    NSDictionary *dict2 = @{@"key":@"efeng",@"text":str1};
    NSString *str2 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict2 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    
    
    NSString *urlStr = [NSString stringWithFormat:@"http://%@:%zd/imconsole/circleContent_listDeleteIds.action?param=%@", M_STOREVALUE(serverSetting.IMIp),serverSetting.IMPort,[self getDesAndBase64WithString:str2]];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    
    
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureHandle(operation,error);
        
        
    }];
    [_queen addOperation:operation];
    return operation;

}
//添加回复或评论
- (void)composeShareCommentWithShareId:(NSString *)shareId commentId:(NSString *)commentId releaseUserId:(NSString *)releaseUserId sendUserId:(NSString *)sendUserId sendUserName:(NSString *)sendUserName receiveUserId:(NSString *)receiveUserId receiveUserName:(NSString *)receiveUserName content:(NSString *)content type:(NSString *)type successHandel:(void (^)(AFHTTPRequestOperation *operation, id responseObject))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failureHandle
{
    [USER_DEFAULT setBool:NO forKey:@"sendOK"];
    [USER_DEFAULT synchronize];
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSDictionary *dict1 = @{@"companyId":M_STOREVALUE(serverSetting.companyId),@"contentId":@(shareId.longLongValue),@"sendUserId":M_STOREVALUE(sendUserId),@"releaseUserId":M_STOREVALUE(releaseUserId),@"sendUserName":M_STOREVALUE(sendUserName),@"receiveUserId":M_STOREVALUE(receiveUserId),@"receiveUserName":M_STOREVALUE(receiveUserName),@"content":M_STOREVALUE(content),@"type":M_STOREVALUE(type),@"id":@(commentId.longLongValue)};
    NSString *str1 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict1 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    NSDictionary *dict2 = @{@"key":@"efeng",@"text":str1};
    NSString *str2 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict2 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    
    
    NSString *urlStr = [NSString stringWithFormat:@"http://%@:%zd/imconsole/contentReply_replyMessage.action?param=%@", M_STOREVALUE(serverSetting.IMIp),serverSetting.IMPort,[self getDesAndBase64WithString:str2]];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [USER_DEFAULT setBool:YES forKey:@"sendOK"];
        [USER_DEFAULT synchronize];
        failureHandle(operation,error);
    }];
    [_queen addOperation:operation];

}
//删除回复
- (void)delShareCommentWithCommentId:(NSString *)commentId date:(NSString *)date successHandel:(void (^)(AFHTTPRequestOperation *operation, id responseObject))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failureHandle
{
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSDictionary *dict1 = @{@"companyId":M_STOREVALUE(serverSetting.companyId),@"date":[NSNumber numberWithLongLong:date.longLongValue],@"id":@(commentId.longLongValue)};
    NSString *str1 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict1 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    NSDictionary *dict2 = @{@"key":@"efeng",@"text":str1};
    NSString *str2 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict2 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    
    
    NSString *urlStr = [NSString stringWithFormat:@"http://%@:%zd/imconsole/contentReply_replyMessageDel.action?param=%@", M_STOREVALUE(serverSetting.IMIp),serverSetting.IMPort,[self getDesAndBase64WithString:str2]];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    
    
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureHandle(operation,error);
        
        
    }];
    [_queen addOperation:operation];

}

//点赞
- (void)praiseShareWithSendUserId:(NSString *)sendUserId commentId:(NSString *)commentId releaseUserId:(NSString *)releaseUserId contentId:(NSString *)contentId sendUserName:(NSString *)sendUserName successHandel:(void (^)(AFHTTPRequestOperation *operation, id responseObject))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failureHandle
{
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSDictionary *dict1 = @{@"companyId":M_STOREVALUE(serverSetting.companyId),@"contentId":@(contentId.longLongValue),@"releaseUserId":M_STOREVALUE(releaseUserId),@"sendUserId":M_STOREVALUE(sendUserId),@"sendUserName":M_STOREVALUE(sendUserName),@"receiveUserId":@"",@"receiveUserName":@"",@"content":@"",@"type":@"praise",@"id":@(commentId.longLongValue)};
    NSString *str1 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict1 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    NSDictionary *dict2 = @{@"key":@"efeng",@"text":str1};
    NSString *str2 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict2 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    
    
    NSString *urlStr = [NSString stringWithFormat:@"http://%@:%zd/imconsole/contentReply_addPraise.action?param=%@", M_STOREVALUE(serverSetting.IMIp),serverSetting.IMPort,[self getDesAndBase64WithString:str2]];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    
    
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureHandle(operation,error);
        
        
    }];
    [_queen addOperation:operation];

}
//取消点赞
- (void)cancelPraiseShareWithCommentId:(NSString *)commentId date:(NSString *)date successHandel:(void (^)(AFHTTPRequestOperation *operation, id responseObject))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failureHandle
{
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSDictionary *dict1 = @{@"companyId":M_STOREVALUE(serverSetting.companyId),@"date":M_STOREVALUE(date),@"id":@(commentId.longLongValue)};
    NSString *str1 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict1 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    NSDictionary *dict2 = @{@"key":@"efeng",@"text":str1};
    NSString *str2 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict2 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    
    
    NSString *urlStr = [NSString stringWithFormat:@"http://%@:%zd/imconsole/contentReply_cancelPraise.action?param=%@", M_STOREVALUE(serverSetting.IMIp),serverSetting.IMPort,[self getDesAndBase64WithString:str2]];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    
    
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureHandle(operation,error);
        
        
    }];
    [_queen addOperation:operation];

}
//获取回复内容
- (AFHTTPRequestOperation *)getShareCommentListWithDate:(NSString *)date shareDate:(NSString *)shareDate userId:(NSString *)userId releaseUserId:(NSString *)releaseUserId findType:(NSString *)findType successHandel:(void (^)(AFHTTPRequestOperation *operation, id responseObject))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failureHandle
{
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSDictionary *dict1 = @{@"companyId":M_STOREVALUE(serverSetting.companyId),@"date":[NSNumber numberWithLongLong:date.longLongValue],@"userId":M_STOREVALUE(userId),@"findType":M_STOREVALUE(findType),@"contentDate":[NSNumber numberWithLongLong:shareDate.longLongValue],@"releaseUserId":M_STOREVALUE(releaseUserId)};
    NSString *str1 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict1 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    NSDictionary *dict2 = @{@"key":@"efeng",@"text":str1};
    NSString *str2 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict2 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    
    
    NSString *urlStr = [NSString stringWithFormat:@"http://%@:%zd/imconsole/contentReply_list.action?param=%@", M_STOREVALUE(serverSetting.IMIp),serverSetting.IMPort,[self getDesAndBase64WithString:str2]];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    
    
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureHandle(operation,error);
        
        
    }];
    
    [_queen addOperation:operation];
    return operation;

}
//获取已删除回复内容ID列表
- (AFHTTPRequestOperation *)getDelShareCommentListWithDate:(NSString *)date userId:(NSString *)userId successHandel:(void (^)(AFHTTPRequestOperation *operation, id responseObject))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failureHandle
{
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSDictionary *dict1 = @{@"companyId":M_STOREVALUE(serverSetting.companyId),@"date":M_STOREVALUE(date),@"userId":M_STOREVALUE(userId)};
    NSString *str1 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict1 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    NSDictionary *dict2 = @{@"key":@"efeng",@"text":str1};
    NSString *str2 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict2 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    
    
    NSString *urlStr = [NSString stringWithFormat:@"http://%@:%zd/imconsole/contentReply_listDeleteIds.action?param=%@", M_STOREVALUE(serverSetting.IMIp),serverSetting.IMPort,[self getDesAndBase64WithString:str2]];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    
    
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureHandle(operation,error);
        
        
    }];
    [_queen addOperation:operation];
    return operation;

}

- (void)addMineAttentionWithUserId:(NSString *)userId successHandel:(void (^)(AFHTTPRequestOperation *, id))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *, NSError *))failureHandle
{
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    
    NSString *localServerAddr = serverSetting.IMIp;
    NSInteger openFirePort = serverSetting.IMPort;
    
    CAccountModel *acc = [[CFolderMgr shareInstance].accMgr getRecentlyLoginAccount];
    
    NSDictionary *dict1 = @{@"userId":M_STOREVALUE(acc.userId),@"meAttentionId":M_STOREVALUE(userId)};
    NSString *str1 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict1 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    NSDictionary *dict2 = @{@"key":@"efeng",@"text":str1};
    NSString *str2 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict2 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    NSString *urlStr = [NSString stringWithFormat:@"http://%@:%zd/imconsole/circleAttention_addAttentionId.action?param=%@", localServerAddr, openFirePort,[self getDesAndBase64WithString:str2]];
    
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    
    
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failureHandle(operation,error);
        
    }];
    [_queen addOperation:operation];

}

- (void)cancelMineAttentionWithUserId:(NSString *)userId successHandel:(void (^)(AFHTTPRequestOperation *, id))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *, NSError *))failureHandle
{
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    
    NSString *localServerAddr = serverSetting.IMIp;
    NSInteger openFirePort = serverSetting.IMPort;
    
    CAccountModel *acc = [[CFolderMgr shareInstance].accMgr getRecentlyLoginAccount];
    
    
    NSDictionary *dict1 = @{@"userId":M_STOREVALUE(acc.userId),@"cancelId":M_STOREVALUE(userId)};
    NSString *str1 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict1 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    NSDictionary *dict2 = @{@"key":@"efeng",@"text":str1};
    NSString *str2 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict2 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];

    
    NSString *urlStr = [NSString stringWithFormat:@"http://%@:%zd/imconsole/circleAttention_cancelAttentionId.action?param=%@", localServerAddr, openFirePort,[self getDesAndBase64WithString:str2]];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    
    
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failureHandle(operation,error);
        
    }];
    [_queen addOperation:operation];

}
- (void)getMineAttentionWithsuccessHandel:(void (^)(AFHTTPRequestOperation *, id))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *, NSError *))failureHandle
{
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    
    NSString *localServerAddr = serverSetting.IMIp;
    NSInteger openFirePort = serverSetting.IMPort;
    
    CAccountModel *acc = [[CFolderMgr shareInstance].accMgr getRecentlyLoginAccount];
    
    NSDictionary *dict1 = @{@"userId":M_STOREVALUE(acc.userId)};
    NSString *str1 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict1 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];
    NSDictionary *dict2 = @{@"key":@"efeng",@"text":str1};
    NSString *str2 = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict2 options:NSJSONWritingPrettyPrinted error:nil] encoding:NSUTF8StringEncoding];

    NSString *urlStr = [NSString stringWithFormat:@"http://%@:%zd/imconsole/circleAttention_listAttentionId.action?param=%@", localServerAddr, openFirePort,[self getDesAndBase64WithString:str2]];
    
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    
    
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureHandle(operation,error);
    }];
    [_queen addOperation:operation];

}

//获取企业信息
-(void)getCompanyInfoWithUserCode:(NSString *)userCode AndsuccessHandel:(void (^)(AFHTTPRequestOperation *, id))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *, NSError *))failureHandle
{
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSString *localServerAddr = serverSetting.IMIp;
    NSInteger openFirePort = serverSetting.IMPort;
    NSString *urlStr = [NSString stringWithFormat:@"http://%@:%zd/imconsole/general_getCompInfo.action?userName=%@", localServerAddr, openFirePort,userCode];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureHandle(operation,error);
    }];
    [_queen addOperation:operation];

}
-(void)getUserInfoWithUserCode:(NSString *)userCode AndsuccessHandel:(void (^)(AFHTTPRequestOperation *, id))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *, NSError *))failureHandle
{
    CServerSettingModel *serverSetting = [[CFolderMgr shareInstance].serSettingMgr getSetting];
    NSString *localServerAddr = serverSetting.IMIp;
    NSInteger openFirePort = serverSetting.IMPort;
    NSRange range ;
    range.location = 8;
    range.length = 16;
    NSString *paddword = [[@"88888888" stringFromMD5] substringWithRange:range];
    NSString *urlStr = [NSString stringWithFormat:@"http://%@:%zd/imconsole/general_getUserInfo.action?userName=%@&password=%@&userCode=%@", localServerAddr, openFirePort,@"admin", paddword,userCode];
    NSString * requestUrl = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureHandle(operation,error);
    }];
    [_queen addOperation:operation];

}
- (NSString *)getDesAndBase64WithString:(NSString *)string
{
    NSDateComponents *com = [UIUtil getCurdateComponents];
    NSString *key = [NSString stringWithFormat:@"%zd%02zdwanzhaotech",com.year,com.month];
    return [string DESEncryptWithKey:key];
}

- (void)loadShareData
{
    
    CShareMgr *shareMgr = [[CShareMgr alloc] init];
    CShareDelMgr *shareDelMgr = [[CShareDelMgr alloc] init];
    CShareCommentDelMgr *comDelMgr = [[CShareCommentDelMgr alloc] init];
    CShareCommentMgr *comMgr = [[CShareCommentMgr alloc] init];
    CContactModel *curContact = [[[CContactMgr alloc] init] loadCurContact];
    CSharePersonMgr *personMgr = [[CSharePersonMgr alloc] init];
    
    
    __block NSArray *array1 = nil;
    __block NSArray *array2 = nil;
    __block NSArray *array3 = nil;
    __block NSArray *array4 = nil;

    
    NSString *date1 = [shareMgr getMaxDateShare];
    NSString *curDate = [UIUtil getCurrentTimeStamp];
    
    NSString *date3 = [comMgr getMaxDateShareComment];
    if (!M_ISSTRNULL(date3)) {
        
    } else {
        date3 = curDate;
        //        date3 = @"1456816235900";
        EFengContent *comment = [[EFengContent alloc] init];
        comment.isLocal = YES;
        comment.shareId = [NSString stringWithFormat:@"isLocal%@",date3];
        comment.date = date3;
        [comMgr insertWithShareComment:comment];
    }

    if (!M_ISSTRNULL(date1)) {
        [[CXmppRequestMgr shareInstance] getShareListWithDate:date1 findType:@"" userId:curContact.UserID releaseUserId:@"" successHandel:^(AFHTTPRequestOperation *operation, id responseObject) {
            
            //         NSLog(@"1111");
            if ([responseObject[@"result"] isEqualToString:@"success"]) {
                array1 = responseObject[@"text"];
                NSArray *shareArray = [EFengShare objectArrayWithKeyValuesArray:array1];
                [shareMgr batchInsertWithShareList:shareArray];
                [personMgr batchInsertWithShareList:shareArray];
                [[NSNotificationCenter defaultCenter] postNotificationName:K_XMPPReceiveShare object:nil];
            }
            
        } filarueHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
            
        }];
        
        
        [[CXmppRequestMgr shareInstance] getShareCommentListWithDate:date3 shareDate:date1 userId:curContact.UserID releaseUserId:@"" findType:@"" successHandel:^(AFHTTPRequestOperation *operation, id responseObject) {
            //         NSLog(@"3333");
            
            if ([responseObject[@"result"] isEqualToString:@"success"]) {
                array3 = responseObject[@"text"];
                NSArray *commentArray = [EFengContent objectArrayWithKeyValuesArray:array3];
                [comMgr batchInsertWithCommentList:commentArray];
                [[NSNotificationCenter defaultCenter] postNotificationName:K_XMPPReceiveComment object:nil];
            }
            
            
        } filarueHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
            
        }];

        
    } else {
        date1 = curDate;
        //         date1 = @"1456816235900";
        EFengShare *share = [[EFengShare alloc] init];
        share.isLocal = YES;
        share.shareId = [NSString stringWithFormat:@"isLocal%@",date1];
        share.date = date1;
        [shareMgr insertWithShare:share];
        [personMgr insertWithShare:share];
        [[CXmppRequestMgr shareInstance] getShareListWithDate:date1 findType:@"down" userId:curContact.UserID releaseUserId:@"" successHandel:^(AFHTTPRequestOperation *operation, id responseObject) {
            
            //         NSLog(@"1111");
            if ([responseObject[@"result"] isEqualToString:@"success"]) {
                array1 = responseObject[@"text"];
                NSArray *shareArray = [EFengShare objectArrayWithKeyValuesArray:array1];
                [shareMgr batchInsertWithShareList:shareArray];
                [personMgr batchInsertWithShareList:shareArray];
                [shareMgr batchUpdateAllUnreadShareToReadShareWithShareList:shareArray];
                [[NSNotificationCenter defaultCenter] postNotificationName:K_XMPPReceiveShare object:nil];
            }

        } filarueHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        }];
        
        [[CXmppRequestMgr shareInstance] getShareCommentListWithDate:date3 shareDate:date1 userId:curContact.UserID releaseUserId:@"" findType:@"down" successHandel:^(AFHTTPRequestOperation *operation, id responseObject) {
            //         NSLog(@"3333");
            
            if ([responseObject[@"result"] isEqualToString:@"success"]) {
                array3 = responseObject[@"text"];
                NSArray *commentArray = [EFengContent objectArrayWithKeyValuesArray:array3];
                [comMgr batchInsertWithCommentList:commentArray];
                [comMgr batchUpdateUnreadCommentToReadCommentWithCommentList:commentArray];
                [[NSNotificationCenter defaultCenter] postNotificationName:K_XMPPReceiveComment object:nil];
            }
            
            
        } filarueHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
            
        }];

    }
    
    NSString *date2 = [shareDelMgr getMaxDateShareDel];
    if (!M_ISSTRNULL(date2)) {
        
    } else {
        date2 = curDate;
        //        date2 = @"1456816235900";
        EFengShareDel *shareDel = [[EFengShareDel alloc] init];
        shareDel.shareId = [NSString stringWithFormat:@"isLocal%@",date2];
        shareDel.date = date2;
        [shareDelMgr insertWithShareDel:shareDel];
    }
    
    [[CXmppRequestMgr shareInstance] getDelShareListWithDate:date2 userId:curContact.UserID successHandel:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        //         NSLog(@"2222");
        
        if ([responseObject[@"result"] isEqualToString:@"success"]) {
            if ([responseObject[@"result"] isEqualToString:@"success"]) {
                array2 = responseObject[@"text"];
                NSMutableArray *idArray = [NSMutableArray array];
                NSArray *shareDelArray =[EFengShareDel objectArrayWithKeyValuesArray:array2];
                
                [shareDelMgr batchInsertShareDelWithDelList:shareDelArray];
                [shareDelArray enumerateObjectsUsingBlock:^(EFengShareDel *obj, NSUInteger idx, BOOL * stop) {
                    [idArray addObject:obj.shareId];
                    [shareMgr delShareWithShareId:obj.shareId];
                    [personMgr delShareWithShareId:obj.shareId];
                }];
                
                [[NSNotificationCenter defaultCenter] postNotificationName:K_XMPPDelShare object:idArray];
            }
            
            
        }
        
    } filarueHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
    
    
    NSString *date4 = [comDelMgr getMaxDateCommentDel];
    if (!M_ISSTRNULL(date4)) {
        
    } else {
        date4 = curDate;
        //        date4 = @"1456816235900";
        EFengShareCommentDel *comment = [[EFengShareCommentDel alloc] init];
        comment.commentId = [NSString stringWithFormat:@"isLocal%@",date4];
        comment.date = date4;
        //        [self.shareCommentDelMgr insertCommentDelWithCommentDel:comment];
    }
    
    
    [[CXmppRequestMgr shareInstance] getDelShareCommentListWithDate:date4 userId:curContact.UserID successHandel:^(AFHTTPRequestOperation *operation, id responseObject) {

        if ([responseObject[@"result"] isEqualToString:@"success"]) {
            if ([responseObject[@"result"] isEqualToString:@"success"]) {
                array4 = responseObject[@"text"];
                NSArray *commentDelArray = [EFengShareCommentDel objectArrayWithKeyValuesArray:array4];
                [comDelMgr batchInsertCommentDelWithDelList:commentDelArray];
                [commentDelArray enumerateObjectsUsingBlock:^(EFengShareCommentDel *obj, NSUInteger idx, BOOL *stop) {
                    [comMgr delShareCommentWithCommentId:obj.commentId];
                }];
                [[NSNotificationCenter defaultCenter] postNotificationName:K_XMPPDelComment object:nil];
            }
            
            
        }
        
    } filarueHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
    
    
}

//消息回执
- (void)sendHuiZhiXiaoxiWithMessageId:(NSString *)messageId
{
    XMPPMessage *aMessage;
    aMessage=[XMPPMessage messageWithType:@"normal" to:[XMPPJID jidWithString:[[CXmppMgr shareInstance] xmppStream].hostName] elementID:messageId];
    [aMessage addAttributeWithName:@"reply" stringValue:@"yes"];
    [[CXmppMgr shareInstance] sendElement:aMessage];

}
- (void)sendUnSendMessage
{
    
}
//更新消息发送失败状态
-(void)updateMessageSendStatusWithMessageId:(NSString*)MessageId
{
    CMessageModel *model = [self.messageMgr loadMessageWithMessageId:MessageId];
    model.MessageSendedStatus = kMessageSendFailed;
    if([self.messageMgr updateMessage:model])
    {
        dispatch_async(dispatch_get_main_queue(), ^{
            [[NSNotificationCenter defaultCenter] postNotificationName:K_XMPPFAILEDRECEIVEMESSAGE object:model.MessageId];
            
        });
    }

}
//红包相关
-(void)getPersonbalanceWithUserId:(NSString *)userID successHandel:(void (^)(AFHTTPRequestOperation *, id))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *, NSError *))failureHandle
{
    NSString *strUrl = [NSString stringWithFormat:@"%@getUserCash.action?id=%@",REDPACKETNET,userID];
    NSString *requestUrl = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    operation.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureHandle(operation,error);
    }];
    [_queen addOperation:operation];
}
-(void)verificationPayPasswordWithUserId:(NSString *)userId AndPassWord:(NSString *)password successHandel:(void (^)(AFHTTPRequestOperation *, id))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *, NSError *))failureHandle
{
     NSString *strUrl = [NSString stringWithFormat:@"%@verificationPayPassword.action?id=%@&password=%@",REDPACKETNET,userId,password];
     NSString *requestUrl = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    operation.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureHandle(operation,error);
    }];
    [_queen addOperation:operation];


}
-(void)changePassWordWithPassword:(NSString *)password AnduserId:(NSString *)userId successHandel:(void (^)(AFHTTPRequestOperation *, id))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *, NSError *))failureHandle
{
    NSString *strUrl = [NSString stringWithFormat:@"%@modifyPayPassword.action?id=%@&password=%@",REDPACKETNET,userId,password];
    NSString *requestUrl = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    operation.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureHandle(operation,error);
    }];
    [_queen addOperation:operation];
    

}
-(void)rechargeMoneyWithUserId:(NSString *)userId AndCash:(double)cash successHandel:(void (^)(AFHTTPRequestOperation *, id))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *, NSError *))failureHandle
{
    NSString *strUrl = [NSString stringWithFormat:@"%@rechargeMoney.action?userId=%@&cash=%f",REDPACKETNET,userId,cash];
    NSString *requestUrl = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    operation.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureHandle(operation,error);
    }];
    [_queen addOperation:operation];
}
-(void)getRedPacketStatusWithUserId:(NSString *)userId AndMessageId:(NSString *)messageId successHandel:(void (^)(AFHTTPRequestOperation *, id))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *, NSError *))failureHandle
{
    NSString *realId;
    NSRange range = [messageId rangeOfString:@"-"];
    if (range.location != NSNotFound) {
        realId = [messageId substringToIndex:range.location];
    }
    else
    {
        realId = messageId;
    }
    NSString *strUrl = [NSString stringWithFormat:@"%@checkRobRedPacket.action?id=%@&userId=%@",REDPACKETNET,realId,userId];
    NSString *requestUrl = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    operation.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureHandle(operation,error);
    }];
    [_queen addOperation:operation];
}
-(void)getMoneyFromRedPacketWithUserId:(NSString *)userId useName:(NSString *)userName messageId:(NSString *)messageId successHandel:(void (^)(AFHTTPRequestOperation *, id))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *, NSError *))failureHandle
{
    NSString *realId;
    NSRange range = [messageId rangeOfString:@"-"];
    if (range.location != NSNotFound) {
        realId = [messageId substringToIndex:range.location];
    }
    else
    {
        realId = messageId;
    }
    NSString *strUrl = [NSString stringWithFormat:@"%@robRedPacket.action?id=%@&userId=%@&userName=%@",REDPACKETNET,realId,userId,userName];
    NSString *requestUrl = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    operation.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureHandle(operation,error);
    }];
    [_queen addOperation:operation];

}
-(void)getredPacketInfoWithMessageId:(NSString *)messageId successHandel:(void (^)(AFHTTPRequestOperation *, id))successHandle filarueHandle:(void (^)(AFHTTPRequestOperation *, NSError *))failureHandle
{
    NSString *realId;
    NSRange range = [messageId rangeOfString:@"-"];
    if (range.location != NSNotFound) {
        realId = [messageId substringToIndex:range.location];
    }
    else
    {
        realId = messageId;
    }
    NSString *strUrl = [NSString stringWithFormat:@"%@getRedPacketReceiveDetail.action?id=%@",REDPACKETNET,realId];
    NSString *requestUrl = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
    NSMutableURLRequest *request = [serializer requestWithMethod:@"GET" URLString:requestUrl parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
    operation.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        successHandle(operation,responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failureHandle(operation,error);
    }];
    [_queen addOperation:operation];
}
@end
